我正在使用animate.js和fullpage.js。我的目标是在滚动部分时添加slideOutLeft动画,并在访问部分时添加slideInLeft动画。
我当前的代码删除了动画中的幻灯片并应用了幻灯片动画,但从未在动画中重新应用幻灯片。
$('#fullpage').fullpage({
afterLoad: function(anchorLink, index) {
$('.text').addClass('animated slideInLeft');
},
onLeave: function(index, nextIndex, direction) {
$('.text').removeClass('animated slideInLeft');
$('.text').addClass('animated slideOutLeft');
}
});
#first {
background-color: yellow;
}
#second {
background-color: blue;
}
.height {
height: 100vh;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.9/jquery.fullPage.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.1/animate.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.9/jquery.fullPage.css" rel="stylesheet" />
<div id="fullpage">
<div class="section height" id="first">
<h2 class="text">Something1</h2>
</div>
<div class="section height" id="second">
<h2 class="text">Something2.</h2>
</div>
<div class="section height" id="third">
<h2 class="text">Something else </h2>
</div>
</div>
答案 0 :(得分:1)
对于onLeave
,您必须使用离开部分查找文本并在slideOutLeft
中应用onLeave
。另请注意,移除slideOutLeft
中的afterLoad
,文本可以将其再次滑出。
$('#fullpage').fullpage({
afterLoad: function(anchorLink, index) {
$(this).find('.text').removeClass('animated slideOutLeft');
$(this).find(".text").css("display","block");
$(this).find('.text').addClass('animated slideInLeft');
},
onLeave: function(index, nextIndex, direction) {
var leavingSection = $(this);
$(leavingSection).find(".text").removeClass('animated slideInLeft');
$(leavingSection).find(".text").addClass('animated slideOutLeft');
}
});