Skip to content

Instantly share code, notes, and snippets.

@mbriggs
Created November 8, 2012 17:27
Show Gist options
  • Select an option

  • Save mbriggs/4040236 to your computer and use it in GitHub Desktop.

Select an option

Save mbriggs/4040236 to your computer and use it in GitHub Desktop.
/* 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