Guest georgene Posted November 1, 2020 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.
Krydos Posted November 1, 2020 Posted November 1, 2020 Maybe this will help? https://stackoverflow.com/a/8028584/2336864
Guest georgene Posted November 1, 2020 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.
Krydos Posted November 1, 2020 Posted November 1, 2020 From the link I posted Cross-Browser Method to Determine Vertical Scroll Percentage in Javascript
Guest georgene Posted November 1, 2020 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.
Guest georgene Posted November 1, 2020 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 } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now