Jump to content

Recommended Posts

Guest georgene
Posted

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.

Guest georgene
Posted

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.

Guest georgene
Posted

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

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
}
 } 

 

 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...