最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Iscroll - Jquery - Get position on a list item - Stack Overflow

programmeradmin3浏览0评论

The error I'm having is the following:

To the right of my page, I have a list of interesting points (displayed on a map to the left of the page). Because the list is so long, I am using iScroll 4 (great plugin).

However, what I would like to do is fire an event when the user has scrolled the list, so I can check which items are currently visible to the user. iScroll already has an event set up for that, so I have a function that fires when needed. However, I cannot seem to get the proper coordinates of my list items.

What happens is the following:

  1. When the list loads, I get an .offset() value for the first element. offset.top = 35, because my list starts 35px lower than the top edge of the page. This is good.
  2. When I scroll the list; say I pull it down for 500px; I would expect the new location to be 35px - 500px = -465px. However, it sill says 35. Scrolling though the list does not affect the elemen'ts coordinates even though it has moved.

How can I get the actual coordinates?

The error I'm having is the following:

To the right of my page, I have a list of interesting points (displayed on a map to the left of the page). Because the list is so long, I am using iScroll 4 (great plugin).

However, what I would like to do is fire an event when the user has scrolled the list, so I can check which items are currently visible to the user. iScroll already has an event set up for that, so I have a function that fires when needed. However, I cannot seem to get the proper coordinates of my list items.

What happens is the following:

  1. When the list loads, I get an .offset() value for the first element. offset.top = 35, because my list starts 35px lower than the top edge of the page. This is good.
  2. When I scroll the list; say I pull it down for 500px; I would expect the new location to be 35px - 500px = -465px. However, it sill says 35. Scrolling though the list does not affect the elemen'ts coordinates even though it has moved.

How can I get the actual coordinates?

Share Improve this question asked Feb 23, 2012 at 12:33 FlaterFlater 13.9k4 gold badges44 silver badges67 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Playing with iScroll, I think I found the solution. the offset() function is javascript refering to the #scroller div, which doesn't change. However internally, iScroll uses its own x and y properties.

So you can refer to the iScroll offset like this

var myScroll = new iScroll(...)
alert(myScroll.y)  // -- will return your offset (negative number)

add in iscroll.js

getScrollY: function () { var that = this; return that.y; }, 
发布评论

评论列表(0)

  1. 暂无评论