Simple function to return scrollTop position in %

window.onscroll = function() { var h = document.documentElement, b = document.body, st = 'scrollTop', sh = 'scrollHeight', percent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; if (percent > 65 && percent < 67) { console.log('BOUYA! ' + percent); } };
Not very elaborate but does the job for some simple stuff.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.