0

I need to hint my user that there are some useful results on next page as soon as he crosses half of the width of my webpage(home). For this, I wish to know the exact position of the scroll bar , so , that as soon as the position of the scroll bar goes after 50% , I can trigger some javascript function to do the same.

I have encircled the scroll bar in the picture whose position, I have to find out

enter image description here

Also, if we can't find out the position of scroll bar, please tell me some alternate method to do the same !

Thanks !!

1
  • I don't know for what purpose you need the position of the scroll bar. But keep in mind that all touch devices and all computers with OS X 10.7 or higher won't show a scroll bar by default. It's visible only for a short time during scrolling. Commented Aug 19, 2012 at 12:14

1 Answer 1

1

You can't find the position of the scrollbar since it's not a part of the DOM but what you can do is determine the position. Since I don't know how to do it with vanilla JavaScript I'll give you a jQuery example:

var scrollTop = $("body").scrollTop(); // pixels scrolled from top
var documentHeight = $(document).height(); // the height of the document

if(scrollTop >= documentHeight / 2){
    // 50%+ scrolled
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.