元素进入屏幕可视区域,触发animate动画

   css:

//需要引入animate.css

[data-animation]{visibility: hidden;animation-duration:1.5s;
-webkit-animation-duration:1.5s;opacity: 0;animation-fill-mode:forwards;}

html:
<div data-animation="fadeInUp" data-delay="0" class="item"></div>

js:

/*滚动animate特效*/
$(window).scroll(function(){
$("[data-animation]").each(function(){
let ani = $(this).attr('data-animation');
let delay = $(this).attr('data-delay')!=undefined?$(this).attr('data-delay')*0.2:0;
let _this = $(this);
if($(window).scrollTop()>($(this).offset().top-$(window).height()+100) && !$(this).attr('animation-status')){
$(this).attr('animation-status','true');

$(this).css({
'visibility':'visible',
'animationName':ani,
'animationDelay':delay+'s'
});
}
});
});
$(window).trigger('scroll');
posted @ 2020-08-05 15:35  myyt  阅读(1268)  评论(0编辑  收藏  举报