滚动到li元素 - jquery [英] scrolling to li element - jquery
本文介绍了滚动到li元素 - jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将ul的滚动位置(使用jquery)更改为特定的li?
有什么想法?
解决方案
:
$('#yourUL')。scrollTop($('#yourUL li:nth-child(14)') 。.POSITION()顶部);
如果要制作动画,请执行
$('#yourUL')。animate({
scrollTop:$('#yourUL li:nth-child(14)')。position()。top
},'slow');
明显调整 14
$ c> li s。
i have a "ul" that contains lots of "li" (several hundred), the ul has a fixed hight of about 400px and the css property overflow:scroll, each li has the height of 40px so in every given moment there are no more then 10 visible li (the rest need to be scrolled to). how can i change the scroll position (using jquery) of the ul to a specific li?
any thoughts?
解决方案
You need to do something like this:
$('#yourUL').scrollTop($('#yourUL li:nth-child(14)').position().top);
If you want to animate it, do
$('#yourUL').animate({
scrollTop: $('#yourUL li:nth-child(14)').position().top
}, 'slow');
Obviously adjust 14
for different li
s.
这篇关于滚动到li元素 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文