Created
October 15, 2014 19:40
-
-
Save silvenon/098bc5afed31718b854e to your computer and use it in GitHub Desktop.
By https://github.com/rediris, extracted from https://github.com/Prinzhorn/skrollr/issues/596#issuecomment-54241421.
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
// DEBOUNCE FUNCTION via @http://davidwalsh.name/javascript-debounce-function | |
function debounce(a,b,c){var d;return function(){var e=this,f=arguments;clearTimeout(d),d=setTimeout(function(){d=null,c||a.apply(e,f)},b),c&&!d&&a.apply(e,f)}} | |
skrollrCheck = debounce(function() { | |
var winWidth = window.innerWidth; | |
if(winWidth >= 600) { | |
// Init Skrollr | |
skrollr.init({ | |
forceHeight: false,//disable setting height on body | |
mobileDeceleration:0.05, | |
render: function(data) { | |
//Debugging - Log the current scroll position. | |
//console.log('data.curTop: ' + data.curTop); | |
} | |
}); | |
skrollr.get().refresh(); | |
} else { | |
// Destroy skrollr for screens less than 600px | |
skrollr.init().destroy(); | |
} | |
}, 250); | |
//Initialize skrollr, but only if it exists | |
if(typeof skrollr !== typeof undefined){ | |
// INITIALIZE | |
window.onload = skrollrCheck(); | |
window.addEventListener('resize', skrollrCheck); | |
} else { | |
console.log('skrollr is missing.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment