Jquery - Safari не будет регистрировать перемещение мыши в плагине - PullRequest
1 голос
/ 11 сентября 2011

Проще говоря, он работает первые несколько раз, когда я тестирую его, затем без каких-либо изменений в коде он останавливается.Здесь он размещен на jsFiddle, он вообще не работает, но вот ссылка: http://jsfiddle.net/x24Te/

А вот код

(function($) {
$.fn.jqScroll = function(options) {
    var $this = this;
    var origin, current, difference;
    var height = this.outerHeight();
    var width = this.outerWidth();
    var stored = [];
    var elem = [];

    var bounds = $this.offset();
    bounds = [bounds.left,bounds.top,bounds.left + width,bounds.top + height];

    init();

    function init() {
        $(document).bind('mousedown',scrollCheck)
    }

    function scrollCheck(e) {
        data = $.data($(e.target).get(0),'events')
        if (data && (data.click || data.mousedown)) return false

        if (e.clientX < bounds[0] || e.clientX > bounds[2] ||
            e.clientY < bounds[1] || e.clientY > bounds[3]) return false

        origin = e.clientY;

        $(document).bind('mousemove',function(e) { scrollMove(e) });
        $(document).bind('mouseup',stopScroll);
    }

    function scrollMove(e) {
        current = e.clientY;
        difference = origin - current;

        $this.children().each(function(a,b) {
            if (!stored[a]) {
                stored[a] = $(this).offset().top
                elem.push(b);
            }
            var y = stored[a];

            $(this).offset({top:y - difference});
        });
    }

    function stopScroll(e) {
        $(document).unbind('mousemove').unbind('mouseup');

        if ($(elem[0]).offset().top > 0) resetElem(-$(elem[0]).offset().top + 30)
        else if ($(elem[elem.length-1]).offset().top < height) resetElem(-$(elem[elem.length-1]).offset().top - 50 + height)
        else {
            stored = [];
            elem = [];
        }
    }

    function resetElem(dir) {
        var dist = $(elem[0]).offset().top - 20;
        $this.children().each(function(a,b) {
            if (!stored[a]) stored[a] = $(this)
            var y = $(this).offset().top - dist;

            $(this).animate({
                top: '+=' + dir
            },1000,function() {
                stored = [];
                elem = [];
            });
        });
    }

    return this
};
})(jQuery);
...