jquery: как исправить быстрое скольжение (карусель)?

0

Я построил слайдер, используя jQuery, который отлично работает, за исключением небольшой проблемы. Ползунок движется быстро, пока настоящий не завершит свое движение.
Особенно это касается второго и третьего слайдов.

Изображение 174551

У кого-нибудь есть решение или альтернатива, чтобы исправить эту проблему?

$.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/

  • 0
    У меня отлично работает.
  • 0
    @MelanciaUK при входе в слайдер1 подходит для одновременного входа в слайд2 и слайд3. дайте мне знать, slider1 и 2 хорошо для вас, пожалуйста.
Показать ещё 4 комментария
Теги:
carousel

1 ответ

2
Лучший ответ

В этот момент вы устанавливаете margin-left на height контейнеров. Исправить это, казалось, исправить это для меня.

    nextPg.testimonial.stop()
        .css({
        'margin-left': dh
    })
        .animate({
        'margin-left': 0
    }, dur);

должно быть

    nextPg.testimonial.stop()
        .css({
        'margin-left': dw
    })
        .animate({
        'margin-left': 0
    }, dur);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню