I have a navigation bar without a
tags:
$('div.nav ul li').on('click', function() {
if($(this).is(':first-child')) {
$("html, body").animate({
scrollTop: "0"
}, 'slow');
} else if($(this).is(':nth-child(2)')) {
$("html, body").animate({
scrollTop: "0"
}, 'slow');
} else if($(this).is(':nth-child(3)')) {
var offset = $('div.features').offset().top;
$("html, body").animate({
scrollTop: offset+ 'px'
}, 'slow');
} else if($(this).is(':nth-child(4)')) {
var offset = $(document).height();
$("html, body").animate({
scrollTop: offset+ 'px'
}, 'slow');
}
});
I wondered if this way is the best way of doing this. first-child & nth-child(2)
goes to the same place, then each child after that - up to 4
has a different position to go to.