感谢一些外部资源以及一些优秀人员的帮助,创建了具有放大效果的following codepen.io图像(后)网格。只有一个小功能实际上我无法弄清楚,例如,如果用户决定调整浏览器宽度,图像将表现得非常非常糟糕,这种JS代码在某种程度上会破坏图像的响应行为,但是如果你刷新页面,一切都会再好看。
JS CODE
$(function(){
$('.item-inner').each(function(){
var img = $(this).find('img');
$(this).css({height:img.height(), width:img.width()});
})
})
答案 0 :(得分:1)
此代码应放在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);