0

私は1.3.2でうまく機能し、1.7.1で壊れているコードを持っていますが、コードが正しくない場合は誰でも私に何を指摘できますか?

(function($){
$.fn.extend({ 
    autoscroll: function(options) {
        return this.each(function() {
            var $this = $(this);
            $this.css({overflow:'hidden'});
            if(options == 'horizontal') $this.mousemove(function(e) {
                var width = $this.width();
                $this.attr({ scrollLeft: ($this.attr('scrollWidth')-width)*(0.5-Math.cos(Math.PI*(e.pageX-$this.offset().left)/width)/2) });
            });
            else if(options == 'vertical') $this.mousemove(function(e) {
                var height = $this.height();
                $this.attr({ scrollTop: ($this.attr('scrollHeight')-height)*(0.5-Math.cos(Math.PI*(e.pageY-$this.offset().top)/height)/2) });
            });
            else if(options == 'both') $this.mousemove(function(e) {
                var width = $this.width(), height = $this.height();
                $this.attr({ scrollLeft: ($this.attr('scrollWidth')-width)*(0.5-Math.cos(Math.PI*(e.pageX-$this.offset().left)/width)/2), scrollTop: ($this.attr('scrollHeight')-height)*(0.5-Math.cos(Math.PI*(e.pageY-$this.offset().top)/height)/2) });
            });
            else $this.mousemove(function(e) {
                var width = $this.width(), height = $this.height();
                $this.attr({ scrollLeft: ($this.attr('scrollWidth')-width)*(0.5-Math.cos(Math.PI*(e.pageX-$this.offset().left)/width)/2), scrollTop: ($this.attr('scrollHeight')-height)*(0.5-Math.cos(Math.PI*(e.pageY-$this.offset().top)/height)/2) });
            });
        });
    }
});
})(jQuery);
4

1 に答える 1

2

attr()HTML属性にのみ使用します。JS / DOMプロパティ(例:scrollWidth、scrollTop)の場合は、prop()

prop()v1.6で導入されました。

デモ: http: //jsfiddle.net/doktormolle/uKMWQ/

于 2012-04-14T23:06:45.567 に答える