开发者

jQuery Content Slider script help

I have on my site a <div> which contains child <div>'s. I want to make those children to slide into place like a content slider. I've tried a couple of different plugins, but they all failed because they tried to do some kind of DOM manipulation that just made things bad...

My own implementation is poor and seems to be having major performance issues.

So, I would like to know if anyone knows of a good content slider that isn'开发者_如何学JAVAt going to screw things up and one that hopefully has good documentation. Don't recommend bxSlider or easySlider, tried them and they failed, especially bxSlider.

Here's how the elements are structured:

<div class="Parent">
    <div>
        <h2>...</h2>
        <ul>
            <li>...</li>
        </ul>
        <p>...</p>
    </div>
    (Repeat)
</div>

Thanks in advance!

EDIT

I've rebuilt my implementation and it's working almost the way I want it to. The problem is that when it reaches the end of the list, it will slide backwards through all items really quick and then start over. Not sure exactly how to fix it. Would appreciate any suggestions!

var interval;

var Slider = function () {
    var width = $(".Parent").width();
    var count = $(".Children").size();
    var margin = width;
    var wrapper = $(".Wrapper");
    var a = 0;

    wrapper.css({
        width: (width * count)
    });

    var interval = window.setInterval(function () {
        if (margin == (width * count)) {
            margin = 0;
            a = 0;
        } else {
            margin = (width * a);
        };

        wrapper.animate({
            marginLeft: ("-" + margin + "px")
        }, 1000);

        a++;
    }, 6000);
};


This one works for me. Maybe it will help you:

<script type="text/javascript">
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

headline_count = $("div.headline").size();

$("div.headline:eq("+current_headline+")").css('top','5px');

headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
$('#scrollup').hover(function() {
        clearInterval(headline_interval);
    }, function() {
        headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
        headline_rotate();
    });

function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count; 
    $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
        $(this).css('top','210px');
    });
    $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
    old_headline = current_headline;
}
</script>

//html

<div id='scrollBox'>
 <div id='scrollup'>
   <div class="headline">...</div>
   <div class="headline">...</div> 
   <div class="headline">...</div> 
 </div>
</div>


I've had the same problem. I've solved using this: (this is a piece of my slide plugin) Apply inside jquery(select_expression).each()

function start()
{

var a=$('div:first',$this);

a.clone().appendTo($this);

$(a).animate({'marginLeft':options.width*-1},options.speed,function(){$(a).remove();});

setTimeout(function() {start();}, delay);

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜