Created
March 15, 2015 06:59
-
-
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.
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
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