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