0
如何确定文本标签与单击的元素匹配的元素索引号?滚动到元素
我有一个列表:
<ul>
<li data-cont="item one">this is one</li>
<li data-cont="item 2">this is second</li>
<li data-cont="one more">this is another one</li>
</ul>
...
<div>item one</div>
<div>item 2</div>
<div>one more</div>
当LIS的一个被点击我的屏幕需要向下滚动到以后在页面上匹配的DIV之一。
$('#li').click(function(){
var scrollNow = $(this).attr('data-cont');
$('html, body').animate({
scrollTop: $(
// here I need to scroll down to the item by index...
).offset().top
}, 500);
});
可能重复http://stackoverflow.com/questions/6677035/jquery-scroll-到元件) –