这是我的代码:
$('.items').html(response).hide().fadeIn();
问题在于当页面加载时,元素首先被渲染出来(具有高度),然后才触发 .hide().fadeIn()
导致页面上下跳动。是否有其他方法可以解决这个问题?
这是我的代码:
$('.items').html(response).hide().fadeIn();
问题在于当页面加载时,元素首先被渲染出来(具有高度),然后才触发 .hide().fadeIn()
导致页面上下跳动。是否有其他方法可以解决这个问题?
如果您想保持元素的尺寸不变,可以使用不透明度:
$('.items').html(response).css({'opacity':0}).animate({'opacity':1});
需要隐藏的部分,可以使用CSS隐瞒起来,然后在需要的时候通过淡入效果展现出来:
CSS代码:
.items {
display:none;
}
JavaScript
$('.items').html(response).fadeIn();
var elem = $(response).css({'opacity': 0});
$('.items').html(elem);
elem.animate({'opacity': 1});
$(function(){
$('.items').fadeOut(function(){
$(this).html(response).fadeIn();
})
});