2

我的页面上有五个 div(#art #fashion、#self、#nightlife、#community)。现在,当您将鼠标悬停在它们上时,它们会将页面内容加载到另一个容器 div (#flyer) 中。

我希望传单内容每 5 秒左右循环一次。

因此,不必将鼠标悬停在这 5 个 div 上,它应该会自动移动。

那有意义吗?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript"> 
$(document).ready(function() { 
        $("#art").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
        $("#fashion").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
        $("#self").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
        $("#nightlife").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
        $("#community").mouseover(function(){ $('#flyer').load($(this).attr("href") + ' #flyer'); return false; }); 
}); 
</script> 
4

2 回答 2

3

另一种方法是setInterval像这样使用函数......

$(document).ready(function() { 
    var sourceElements = $("#art,#fashion,#self,#nightlife,#community");
    var pointer = 0;
    setInterval(function() {
        $('#flyer').load($(sourceElements[pointer++]).attr("href") + ' #flyer');
        if (!sourceElements[pointer]) pointer = 0;
    , 5000}); 
}); 
于 2010-02-26T21:53:39.390 回答
2

我喜欢结合使用 jquery 循环 ( http://malsup.com/jquery/cycle/ ) 来循环内容和 jquery 缓动 ( http://gsgd.co.uk/sandbox/jquery/easing/ ) 来添加一些动画实现这一目标的效果

于 2010-02-26T19:07:47.070 回答