Code: link
I want to make the scroll bar focus the LI element with the class. Keep following the element every time the class is changed. It gives current shape, scrolling is out of sync, going up and down.
Code: link
I want to make the scroll bar focus the LI element with the class. Keep following the element every time the class is changed. It gives current shape, scrolling is out of sync, going up and down.
You need in this case to subtract the position of #playlist
using scrollTop: $(proximo).offset().top - $('#playlist').offset().top
.
I also leave a suggestion to compress the code:
$("#playlist-content input[type=button]").click(function(){
var playing = $('#playlist li.music-playing');
$('#playlist li').removeClass('music-playing');
var proximo = this.id == 'next' ? playing.next() : playing.prev();
if (!proximo.length) proximo = playing;
proximo.addClass('music-playing');
$('#music').animate({
scrollTop: $(proximo).offset().top - $('#playlist').offset().top
}, 500);
});