lstanczyk
lstanczyk

Reputation: 1393

Jquery code that got broken after upgrading to 1.7.1 from 1.3.2

I have a piece of code that works just fine in 1.3.2 and is broken in 1.7.1 can anybody point me to what if not correct with the code:

(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);

Upvotes: 0

Views: 196

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117314

Use attr() only for HTML-attributes. For JS/DOM-properties (e.g. scrollWidth, scrollTop) use prop()

prop() has been introduced in v1.6.

Demo: http://jsfiddle.net/doktormolle/uKMWQ/

Upvotes: 2

Related Questions