How to focus a scroll based on the current selection class

I'm trying to focus the scroll based on the selected add class, when I click on the previous and next scroll buttons, I need to focus it. how can i do this please check my fiddle https://jsfiddle.net/kannankds/bcszkqLu/

<ul class="kds"> <li>tile dtls1</li> <li>tile dtls2</li> <li>tile dtls3</li> </ul> <input type="button" value="previous" class="previous"> <input type="button" value="next" class="next"> 
+5
source share
2 answers

Add

 $(".kds").scrollTop(($(".currentSelection").index()-2) * $(".currentSelection").outerHeight()); 

for previous and

 $(".kds").scrollTop($(".currentSelection").index() * $(".currentSelection").outerHeight()); 

for next

UPDATED FIDDLE

+4
source

You can animate your scroll using scrollTop , for example:

 $('.kds').animate({'scrollTop' : (current.index()) * 30},1000); 

Here 30, because whether your height + top + top of the bottom.

Working script

+3
source

Source: https://habr.com/ru/post/1242771/


All Articles