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

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...