[英]Image resize within the div on manual browser width change
多亏了一些外部资源和一些出色人士的帮助,创建了以下在胡佛上具有放大效果的codepen.io image(post)网格。 我实际上不知道只有一个小功能,例如,如果用户决定改变其浏览器的宽度,图像将表现得非常不好,这种JS代码会破坏图像的响应行为,但是如果您刷新页面,一切将再次看起来不错。
JS代码
$(function(){
$('.item-inner').each(function(){
var img = $(this).find('img');
$(this).css({height:img.height(), width:img.width()});
})
})
这段代码应该放在resize()事件中,也应该放在ready()中
function updateImageSize(){
$('.item-inner').each(function(){
var img = $(this).find('img');
$(this).css({height:img.height(), width:img.width()});
})
}
$(window).on('resize',updateImageSize);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.