Jquery: Scroll to last <li>

floatleft picture floatleft · Dec 1, 2011 · Viewed 12.5k times · Source

I'm using the following to scroll to the last <li> in an unordered list:

$("html,body").animate({scrollTop: $('ul#cart-items li').offset().top});

How can I change this to scroll to the last <li> in the unordered list, but also offset it about 30px from the top?

Answer

Kai Qing picture Kai Qing · Dec 1, 2011

Have you tried this:

$("html,body").animate({scrollTop: $('ul#cart-items li:last').offset().top - 30});

but + or - the 30 at the end to achieve your desired offset?