Skip to content

Instantly share code, notes, and snippets.

@besimhu
Created March 15, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besimhu/eb992a767d272c5b20d1 to your computer and use it in GitHub Desktop.
Save besimhu/eb992a767d272c5b20d1 to your computer and use it in GitHub Desktop.
Enable or disable touch scrolling on phones. This is only best for when you have a fixed menu that takes the view port view and does not scroll at all. See wiki for menu in action.
module.exports = function() {
var $nav = $('.nav-global'),
$toggle = $('.menu-trigger'),
$active_class = 'nav-active',
prevent_default = function(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
},
disable_scroll = function() {
$('body').bind('touchmove', function(e){
e.preventDefault();
});
console.log('scroll disable');
},
enable_scroll = function() {
$('body').unbind('touchmove');
console.log('scroll enable');
};
// Toggle navigation
$toggle.on('click touch', function(){
$('body').toggleClass($active_class);
// Disable touch scrolling if nav is active
if ( $('body').hasClass($active_class) ) {
disable_scroll();
} else {
enable_scroll();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment