Last active
December 11, 2015 17:18
-
-
Save ggendre/4633210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Use this to enable divs with overflow:scroll to scroll in android <3 web views. | |
Useful for phonegap apps. | |
Be sure to test for device first. | |
Usage example (needs jquery or zepto lib): | |
if (android_2){ | |
enableTouchScroll( $('#myCrollableContent'), { x: true, y: true } ); | |
} | |
*/ | |
function enableTouchScroll(selector, axis){ | |
if ( ! axis ) axis = { x : false, y : true } | |
var scrollStartPosTop = 0; | |
var scrollStartPosLeft = 0; | |
$(selector).live('touchstart', function( event ){ | |
if ( axis.y ) scrollStartPosTop = this.scrollTop + event.originalEvent.touches[0].pageY; | |
if ( axis.x ) scrollStartPosLeft = this.scrollLeft + event.originalEvent.touches[0].pageX; | |
}); | |
$(selector).live('touchmove', function( event ){ | |
if ( axis.y ) this.scrollTop = scrollStartPosTop - event.originalEvent.touches[0].pageY; | |
if ( axis.x ) this.scrollLeft = scrollStartPosLeft - event.originalEvent.touches[0].pageX; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment