简体   繁体   English

阻止移动用户下载桌面轮播图片

[英]Prevent mobile users from downloading desktop carousel images

I'd like a static background image to become a carousel at a certain (desktop-ish) breakpoint. 我希望静态背景图片在某个(桌面式)断点处成为轮播。 Would it be possible for me to prevent the mobile user from downloading those carousel images? 我是否可以阻止移动用户下载这些轮播图片? As far as I'm aware a media query won't be enough here. 据我所知,媒体查询在这里还不够。

I'm not referring to the user manually downloading the images to save to their device, I mean their browser doing so automatically. 我指的不是用户手动下载图像以保存到设备,而是指浏览器自动执行。

Media Queries will perfectly solve this issue. 媒体查询将完美解决此问题。

/* Mobile-first */
element {
   background-image:url("small image here");
}


/* Desktop */
@media screen and (min-width: 1024px) {

  element {
     background-image:url("large image here");
  }
}

If you use this code and have your browser at a size greater than 1024px and using the developer tools, inspect the element, you will see the large version of the image being used as the source for the background. 如果使用此代码,并使浏览器的大小大于1024px,并使用开发人员工具,请检查该元素,您将看到图像的大版本用作背景源。 If you then shrink your browser below 1024, you will see the source change to the small version. 如果然后将浏览器缩小到1024以下,您将看到源更改为小版本。 Browsers will only download the value of the source for the image, so a mobile user will never wind up downloading the large version. 浏览器将仅下载图像源的值,因此移动用户永远不会下载大型版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM