从1.3.2升级到1.7.1后破解的Jquery代码

时间:2012-04-14 22:59:51

标签: jquery

我有一段代码在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);

1 个答案:

答案 0 :(得分:2)

仅将attr()用于HTML属性。对于JS / DOM属性(例如scrollWidth,scrollTop),请使用prop()

prop()已在v1.6中引入。

演示:http://jsfiddle.net/doktormolle/uKMWQ/