[英]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.