Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get window scroll or scrollY position in yui

Tags:

javascript

yui

In YUI I have following code working for mouse wheel. How do I make this work for a scrollbar?

Y.on('mousewheel', function(e) {
     var dir = e.wheelDelta > 0 ? 'Up' : 'Down';
     console.log(dir);
});

Thanks for any help...

like image 597
TroodoN-Mike Avatar asked Jun 20 '12 08:06

TroodoN-Mike


People also ask

How do you get the scroll bar position?

How can I get the scrollbar position? To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.

Which of the following method scrolls the window position to the absolute X Y location?

The scrollTo() method scrolls the document to specified coordinates.

How do I know if my scroll is at the top?

You can check if window. scrollY (the number of pixels the window has scrolled vertically) is equal to 0 . If you want to check if the window has been scrolled to its leftermost, you can check if window. scrollX (the number of pixels the window has scrolled horizontally) is equal to 0 .

How do you find the height of a scroll?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.


1 Answers

it was a simple solution

Y.on('scroll', function(e) {     
     console.log(window.scrollY);
});
like image 113
TroodoN-Mike Avatar answered Sep 30 '22 18:09

TroodoN-Mike