0

我正在使用一些 JavaScript 和 jQuery(带有缓动插件)来创建一个虚拟游览;真的只是一个可以左右平移的长图像。我发现这是完美的原因:http: //jsfiddle.net/MvRdD/1/。有没有办法给动画添加缓动?

4

1 回答 1

2

http://jsfiddle.net/ARTsinn/MvRdD/890/

$(document).ready(function() {
    $.getScript("https://raw.github.com/danro/easing-js/master/easing.min.js");
    var animateTime = 10,
        offsetStep = 5,
        scrollWrapper = $('#wrap');

    //event handling for buttons "left", "right"
    var aktiv;
    $('.bttL, .bttR').mousedown(function(e) {
        if (e.target.className === 'bttR') {
            aktiv = window.setInterval(function() {
                scrollWrapper.animate({
                    scrollLeft: '+=' + 20
                }, {
                    duration: 600,
                    queue: false,
                    easing: 'easeOutCirc'
                });
            }, 10);
        } else if (e.target.className === 'bttL') {
            aktiv = window.setInterval(function() {

                scrollWrapper.animate({
                    scrollLeft: '-=' + 20
                }, {
                    duration: 1200,
                    queue: false,
                    easing: 'easeOutCirc'
                });
            }, 10);

        }
    }).mouseup(function() {
        window.clearInterval(aktiv);
    });


    scrollWrapper.mousedown(function(event) {
        $(this).data('down', true).data('x', event.clientX).data('scrollLeft', this.scrollLeft);
        return false;
    }).mouseup(function(event) {
        $(this).data('down', false);
    }).mousemove(function(event) {
        if ($(this).data('down')) {
            $(this).stop(false, true).animate({
                scrollLeft: $(this).data('scrollLeft') + ($(this).data('x') - event.clientX) * 2
            }, {
                duration: 600,
                queue: false,
                easing: 'easeOutCirc'
            });
        }
    }).mousewheel(function(event, delta) {
        $(this).stop(false, true).animate({
            scrollLeft: '-=' + delta * 60
        }, {
            duration: 400,
            queue: false,
            easing: 'easeOutCirc'
        });
        event.preventDefault();
    }).css({
        'overflow': 'hidden',
        'cursor': '-moz-grab'
    });
});
于 2012-09-17T14:30:12.367 回答