开发者

jquery auto scroller

I have a div and I would like to auto scroll it every 5 seconds, can I do that wi开发者_StackOverflow社区th JQuery?


Based on your comment with the demo link, you probably want the Cycle plug-in then: http://jquery.malsup.com/cycle/

Yes it will work with any tags, not just images. If you want to cycle through several <div> tags you could do something like so:

<div class="slideshow">
    <div>Test 1</div>
    <div>Test 2</div>
    <div>Test 3</div>
</div>

It will cycle through any tags within the slideshow class.


Check out the scrollTop() function...

http://api.jquery.com/scrollTop/


There is coda slider plugin which is quite similar.

http://www.ndoherty.biz/demos/coda-slider/2.0/

And there is this tutorial for a custom one if you want to create your own,

http://jqueryfordesigners.com/coda-slider-effect/

Hope these helps, Sinan.


<!doctype html>
<html>
<head>
<title>JQuery Cycle Plugin - Example Slideshow</title>
<style type="text/css">
.slideshow { height: 232px; width: 232px; margin: auto }
.slideshow img { padding: 15px; border: 1px solid #ccc; background-color: #eee; }
</style>
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js"></script>

<!--  initialize the slideshow when the DOM is ready -->
<script type="text/javascript">
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'shuffle' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });
});
</script>
</head>
<body>
    <div class="slideshow">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg" width="200" height="200" />
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="200" height="200" />
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach3.jpg" width="200" height="200" />
    </div>
</body>
</html>

that is exacly what I want, but I want it to work with tags instead of images...can I modify it to work?


var scrolling = window.setInterval("autoScroll()", 5000);

function autoScroll(elem) {

    $(function() {
        $('div#mycontainer').animate({ scrollTop: '+=' + 40 });
    });

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜