Make DIV Scrollbar follow item li from the list

3
Hello, I would like to know how I can make the code I have (below) cause every time the "Next" or "Previous" button "are clicked, follow the li element with the class" music-playing "?

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.

    
asked by anonymous 26.08.2014 / 21:41

1 answer

2

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);

}); 

link

    
27.08.2014 / 05:59