0

小さな問題を除いて正常に動作する jQuery を使用してスライダーを作成しました。現在のスライダーが移動を完了する前に、スライダーがすばやく移動します。
特に2番目と3番目のスライド移動に問題があります

ここに画像の説明を入力

この問題を解決するための解決策または代替手段はありますか?

$.fx.speeds._default = 1000;
function slider(container) {
    var currPg = null,
        firstPg = null;
    container.find('> *').each(function (idx, pg) {
        pg = $(pg);
        var o = {
            testimonial: pg.find('> .testimonial'),
            thumb: pg.find('> .testimonial-thumb'),
            pg: pg
        };
        o.pg.css({
            position: 'absolute',
            width: '100%',
            height: '100%',
        });
        if (idx > 0) {
            o.pg.css({
                opacity: 0,
                    'z-index': -1
            });
            o.testimonial.css({
                'margin-left': '100%'
            });
            o.thumb.css({
                'bottom': '-100%'
            });
        } else {
            firstPg = o;
        }
        o.prev = currPg;
        if (currPg) {
            currPg.next = o;
        }
        currPg = o;
    });
    firstPg.prev = currPg;
    currPg.next = firstPg;
    currPg = firstPg;
    this.advance = function advance(duration) {
        console.log("advance!", this);
        var dur = duration || $.fx.speeds._default;
        var dur2 = Math.ceil(dur / 2);
        var dh = container.height();
        var dw = container.width();
        var nextPg = currPg.next;
        nextPg.pg.css({
            opacity: 1,
                'z-index': null
        });
        var _pg = currPg;
        currPg.testimonial.stop().animate({
            'margin-left': -dw
        }, dur, function () {
            _pg.pg.css({
                opacity: 0,
                    'z-index': -1
            });
            _pg = null;
        });
        nextPg.testimonial.stop()
            .css({
            'margin-left': dh
        })
            .animate({
            'margin-left': 0
        }, dur);
        currPg.thumb.stop().animate({
            'bottom': -dh
        }, dur2, function () {
            nextPg.thumb.stop()
                .css({
                'bottom': -dh
            })
                .animate({
                'bottom': 0
            }, dur2);
            nextPg = null;
        });
        currPg = nextPg;
    }
}
var s = new slider($('#banner'));
function scheduleNext() {
    setTimeout(function () {
        s.advance();
        scheduleNext();
    }, 5000);
}
scheduleNext();

デモhttp://jsfiddle.net/sweetmaanu/Pn2UB/13/

4

1 に答える 1