我有以下 Jquery 文本飞入动画器(请参见下面的代码)。现在我希望一旦用户将鼠标悬停在任何正在动画的元素上,动画就会停止。另外,我希望最后一个元素(Text6)在淡出之前暂停一段时间。我尝试申请:
if ($activeText.is('.lastClass'))
{$activeText.animate.delay(5000) OR $activeText.delay(5000)};
但它不起作用。如何在最后一个 div 上暂停动画?
查询:
<script type="text/javascript">
$(document).ready(function(){
$('.container .flying-text').css({opacity:0});
$('.container .active-text').animate({opacity:1, marginLeft: "0px"}, 1500); //animate first text
var int = setInterval(changeText, 2000); // call changeText function every 5 seconds
function changeText(){
var $activeText = $(".container .active-text"); //get current text
var $nextText = $activeText.next(); //get next text
/*if($activeText.next().length == 0) $nextText = $('.container .flying-text:first');
$activeText.animate({opacity:0}, 1000);
$activeText.animate({marginLeft: "-100px"});*/
if ($activeText.next().length == 0) {
$nextText = $('.container .flying-text:first'); //if it is last text, loop back to first text
// To fade all out
var $allText = $(".container div");
$allText .animate({
opacity: 0
}, 1000);
$allText .animate({
marginLeft: "-100px"
});
}
$nextText.css({opacity: 0}).addClass('active-text').animate({opacity:1, marginLeft: "0px"}, 1500, function(){
$activeText.removeClass('active-text');
});
}
});
</script>
HTML:
<div class="flying1">
<div class="flying-text active-text">Text1</div>
<div class="flying-text">Text2</div>
<div class="flying-text">Text3</div>
<div class="flying-text">Text4</div>
<div class="flying-text">Text5</div>
<div class="flying-text lastClass">Text6</div>
</div>
谢谢你!