开发者

iScroll: Track Y Coordinate to addClass on Scroll

开发者 https://www.devze.com 2023-03-03 01:57 出处:网络
When I log myScroll.y and myScrollPagesY, I get this: var myScroll; function loaded() { myScroll = new iScroll(\'wrapper\', {

When I log myScroll.y and myScrollPagesY, I get this:

var myScroll; 
function loaded() { 
        myScroll = new iScroll('wrapper', { 
                snap: 'div', 
        momentum: false}); 
console.log(myScroll.y); 
console.log(myScroll.pagesY); 
} 

Output:

0

0, -422, -465

So, the default numerical value is 0, but while I scroll I don't see the number change in the console.

Do I have to somehow incorporate the iScroll refresh(); method to constantly update the Y coordinate?

How would I write an if statement that basically said:

if myScroll.y = a certain number then add the class "selected" to the nav button.

Basically, as you are scrolling down the page I want the nav bar开发者_StackOverflow中文版 at the top to highlight when you hit a new section.

Thanks in advance!


You can use the onScrollMove-event. Attach a method to this iScroll-property. The first argument is the scrollerobject. Now read the y-value.

function onScrollMove(scroller, e) {
  //read scroller.y or scroller.currPageY, or whatever property you want to use :)
};
0

精彩评论

暂无评论...
验证码 换一张
取 消