Guest georgene Posted November 1, 2020 Share Posted November 1, 2020 I would like to know how to use pourcentage instead of pixels in that javascript code. if (document.body.scrollTop > 1 || document.documentElement.scrollTop > 1) I know this sounds really obvious but I don't know and can't find anything online about that. Thank you. Quote Link to comment Share on other sites More sharing options...
Krydos Posted November 1, 2020 Share Posted November 1, 2020 Maybe this will help? https://stackoverflow.com/a/8028584/2336864 Quote Link to comment Share on other sites More sharing options...
Guest georgene Posted November 1, 2020 Share Posted November 1, 2020 What I mean is instead of 1 pixel in the line of code, I want it to be 1%. Just writing 1% doesn't work. Quote Link to comment Share on other sites More sharing options...
Krydos Posted November 1, 2020 Share Posted November 1, 2020 From the link I posted Cross-Browser Method to Determine Vertical Scroll Percentage in Javascript Quote Link to comment Share on other sites More sharing options...
Guest georgene Posted November 1, 2020 Share Posted November 1, 2020 I saw what you sent, but my question is about javascript synthax. The line of code I sent means when user scrolls 1 pixel, do whatever. But what I want to write is when user scrolls 1% of the page, do whatever. Quote Link to comment Share on other sites More sharing options...
Guest georgene Posted November 1, 2020 Share Posted November 1, 2020 I just understood what you are telling me to do. { var h = document.documentElement, b = document.body, st = 'scrollTop', sh = 'scrollHeight'; var percent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; if (percent > 1) { //do whatever } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.