davetayls / jquery.kinetic

Add kinetic scrolling functionality to a container using mouse or touch devices
http://davetayls.me/jquery.kinetic
MIT License
420 stars 85 forks source link

Velocity does not work #92

Open BB-000 opened 8 years ago

BB-000 commented 8 years ago

Don't know about other use cases - in my case i was applying kinetic to the body, and using it to scroll around a fixed size div. It scrolled but the deceleration functions were not being called. I don't know if this issue would happen if kinetic was applied to other elements (i assume not?) But again, time is tight, no time to test! :p

This was because of : [line 410]

if (settings.x && scroller.scrollWidth > 0) { ..decelerate.. }

Where scrollWidth was being returned as a number , I checked its value and it was often 0, sometimes - or + by varying random seeming amounts

Taking out the tests for scroller.scrollWidth > 0 fixed the issue,

I don't have time to fully investigate but maybe an extra test to see if the kinetic object is body, don't check for scrollWidth/Height?

Cheers for the plugin anyway dude ,

Merry Christmas ;)

tsaikd commented 8 years ago

I have the same issue with scroller.scrollWidth, maybe @davetayls could explain that.

But I found a method to work around.

var $element = $("#dom");
$element.kinetic();
var kinetic = $element.data($.Kinetic.DATA_KEY);
kinetic._getScroller = function() {
    return {
        scrollLeft: function(left) {}, // custom scrollLeft function
        scrollTop: function(top) {}, // custom scrollTop function
        0: {
            scrollWidth: 1,
            scrollHeight: 1
        }
    };
};
davetayls commented 8 years ago

Scroll properties are sometimes attached to 'html' and sometimes 'body' depending on browsers. Have you tried $('html,body').kinetic()?

It was a very long time ago but I remember this coming up before but never had to tackle it myself. Maybe check through old issues.

Finally you can alter methods on Kinetic via its prototype $.Kinetic.prototype

Hope that helps On Sat, 5 Dec 2015 at 21:53, Tsai KD notifications@github.com wrote:

I have the same issue with scroller.scrollWidth, maybe @davetayls https://github.com/davetayls could explain that.

But I found a method to work around.

var $element = $("#dom"); $element.kinetic(); var kinetic = $element.data($.Kinetic.DATA_KEY); kinetic._getScroller = function() { return { scrollLeft: function(left) {}, // custom scrollLeft function scrollTop: function(top) {}, // custom scrollTop function 0: { scrollWidth: 1, scrollHeight: 1 } }; };

— Reply to this email directly or view it on GitHub https://github.com/davetayls/jquery.kinetic/issues/92#issuecomment-162250486 .