i have horizontal book page image thumbnail ul li, more than 100 image, i have given text box to enter page number to active that page and view that page, it is working without any problem but it is not auto scrolling to that active li in ul, i'm beginner to JavaScript please help me with this, bellowis my code
HTML
<div class="book-list-headbox">
<div class="page-number-box">
<label for="" id="total-page" value="" class="mb-0"></label>
<span class="separator">of</span>
<input type="text" id="current-page" value="1">
</div>
</div>
<ul class="book-list" id="book-list">
<?php if ($total_page > 0) : ?>
<?php foreach ($results as $row) : ?>
<li class="book">
<span class="page-number" id="active-page-number"><?php echo $page_num++ ?></span>
<img src="<?php echo PAGE_URL . "/" . $b_id . "/" . $row->page_name ?>" alt="Book Page">
</li>
<?php endforeach ?>
<?php endif ?>
</ul>
JavaScript
var bookCurrentPages = $('.book #active-page-number');
$('#current-page').keypress(function(e) {
var userInput = $('#current-page').val();
if (this.value.length == 0 && e.which == 48){
// disable enter zero
return false;
}
else if (e.keyCode == 13) {
bookCurrentPages.each(function (key) {
var numKey = key + 1;
if (userInput == numKey) {
// console.log(numKey + " success");
var currentKey = userInput;
// console.log(currentKey);
$('#book-list li:nth-child('+ currentKey +')').children('img').trigger('click');
}
})
return false; // prevent the button click from happening
}
});
Demo check my codes, https://jsfiddle.net/Looper/dmug0zxz/1/