滚动到li元素 - jquery [英] scrolling to li element - jquery

查看:96
本文介绍了滚动到li元素 - jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多li(几百个)的ul,ul的固定高度约为400px,css属性溢出:scroll,每个li的高度都是40px,因此在每个给定的时刻没有更多的可见的李(其余的需要滚动到)。
如何将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 lis.

这篇关于滚动到li元素 - jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆