Created
November 8, 2012 17:27
-
-
Save mbriggs/4040236 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* global Underscore jQuery console */ | |
| ;(function($){ | |
| // this is required to solve virtually any problem | |
| var logAllTheThings = false; | |
| function log(){ | |
| if(console && logAllTheThings) console.log.apply(console, arguments); | |
| } | |
| /// block all scrolling except on scrollable elements | |
| document.addEventListener('touchmove', blockScrolling, true); | |
| var blockScrolling = function (e) { | |
| var scrollable = false, | |
| target = e.target, | |
| parents = $(target).parents(); | |
| console.log("HI!!!!!!!!!!!!!!!!!"); | |
| if( $(target).hasClass('allow-scrolling') ){ | |
| scrollable = true; | |
| } else { | |
| $(parents).each(function(i, parent) { | |
| if( $(parent).hasClass('allow-scrolling') ) scrollable = true; | |
| }); | |
| } | |
| if(!scrollable) e.preventDefault(); | |
| } | |
| /// API | |
| $.fn.allowScrolling = function(){ | |
| var win = $(window); | |
| this.each(function(i, el){ | |
| // make scrollable elements have webkit scrolling reset manually on page resize | |
| var handler = _.debounce( _.bind(resetOverflowScrolling, el), 500, true ); | |
| win.resize(handler); | |
| // prevent overscrolling | |
| $(el). | |
| addClass("allow-scrolling"). | |
| touchwipe({ wipeDown: function(e){ blockOverScrolling(e, this, "up") }, | |
| wipeUp: function(e){ blockOverScrolling(e, this, "down") }, | |
| min_move_x: 50, | |
| min_move_y: 10, | |
| preventDefaultEvents: false }) | |
| }); | |
| } | |
| function resetOverflowScrolling(){ | |
| var el = $(this); | |
| el.css({ webkitOverflowScrolling: 'auto' }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment