得到這個圖像列表。我想顯示距離瀏覽器頂部200px最接近的數字的data-id值。看到我向下滾動,我看到值740,然後756,然後788等根據頂部的位置獲取屬性值
<div id="counter" style="position:fixed;top:10px;left:10px;height:200px;width:200px;"></div>
<figure style="height:200px;" data-id="740"></figure>
<figure style="height:200px;" data-id="756"></figure>
<figure style="height:200px;" data-id="788"></figure>
<figure style="height:200px;" data-id="920"></figure>
哪裏是你的代碼? JSfiddle吧? – 2014-12-06 11:44:49
http://jsfiddle.net/skiweather/2uwpq1w0/ – mark 2014-12-06 12:02:20