简体   繁体   English

调整浏览器窗口大小时更改图像

[英]Change Image when Browser Window is Resized

I have a slideshow on my home page that uses images in a landscape orientation. 我的主页上有一个幻灯片放映,它以横向使用图像。 However, when the browser is resized, the images eventually get clipped. 但是,当调整浏览器的大小时,图像最终会被剪切。 To prevent this, I want to swap the landscape-oriented images to square ones when the browser reaches a certain pixel width. 为了防止这种情况,我想在浏览器达到某个像素宽度时将面向横向的图像交换为正方形图像。 But it must switch back when expanded again. 但是当再次扩展时,它必须切换回去。 How would I go about this? 我将如何处理?

jQuery provides this resize event , And you can use it like, jQuery提供了此resize事件 ,您可以像这样使用它,

$(function() {
   $(window).resize(function() {
      var width = $(window).width();
      var height = $(window).height();

      $('yourimage').attr('src', toAnotherSource);
      // or you can do anything with the image here.
   });
});

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

相关问题 调整浏览器窗口大小时,缩放图像而不是在文本周围环绕文本 - Scale an image instead of wrapping text around it when the browser window is resized 调整浏览器大小时更改占位符 - Change placeholder when browser is resized 调整浏览器窗口大小时禁用jquery插件 - Disable jquery plugin when browser window is resized 调整浏览器窗口大小时如何更改正文宽度,以使内容易于阅读? - How to change the body width when the browser window is resized, so that the content is easily read? 调整浏览器窗口大小时,全屏背景图像仅全屏显示 - Full screen background image only full screen when browser window is resized 如果调整浏览器大小,则更改变量的值 - Change value of variable if/when browser is resized javascript canvas 如果调整浏览器 window 的大小,则只绘制第二张图片 - javascript canvas only drawing second image if the browser window is resized 调整大小后,我的页脚将不会保留在浏览器窗口的底部 - My footer will not remain at the bottom of the browser window when it is resized 调整浏览器窗口大小时,使Canvas动态调整大小 - Get Canvas to dynamically resize when browser window is resized 调整浏览器窗口大小时,防止缩放SVG元素 - Prevent a SVG element to be scaled when the browser window is resized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM