Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 46282  / 14 Years ago, mon, january 3, 2011, 12:00:00

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?


More From » jquery

 Answers
54

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.


[#94404] Friday, December 31, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shianncaylinc

Total Points: 502
Total Questions: 80
Total Answers: 105

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
;