fadeOut()
是jQuery提供的一个内置动画方法,用于通过改变元素的透明度(opacity)来实现淡出效果。当与缩放动画结合使用时,可以创建元素同时淡出和缩小的视觉效果。
$(selector).fadeOut([duration], [easing], [complete]);
duration
: 动画持续时间(毫秒或"slow"/"fast")easing
: 动画缓动函数(默认为"swing")complete
: 动画完成后的回调函数$("#element").css({
'transition': 'transform 500ms ease-in-out',
'transform': 'scale(0)'
}).fadeOut(500);
$("#element").animate({
opacity: 0,
width: 0,
height: 0
}, 500, function() {
$(this).hide();
});
.fade-scale-out {
opacity: 0;
transform: scale(0);
transition: all 0.5s ease;
}
$("#element").addClass("fade-scale-out");
原因:可能由于浏览器重绘/回流导致性能问题
解决方案:
#element {
will-change: transform, opacity;
transform: translateZ(0);
}
原因:fadeOut()仅设置display:none,不改变元素尺寸
解决方案:
$("#element").animate({
opacity: 0,
width: 0,
height: 0,
padding: 0,
margin: 0
}, 500, function() {
$(this).hide();
});
原因:CSS和jQuery动画时间不一致
解决方案:确保CSS transition时间和jQuery动画时间相同
$("#element")
.animate({ opacity: 0.5 }, 200)
.animate({ transform: 'scale(0.8)' }, 200)
.animate({ opacity: 0 }, 200)
.animate({ transform: 'scale(0)' }, 200, function() {
$(this).hide();
});
没有搜到相关的沙龙