var totalList = $('#book-list li').length;
$('#total-page').text(totalList);
$("#book-list li").click(function(e) {
// if i use this getting undefined
// var src = $(this).attr("src");
// so i use this method
var target = e.target;
var src = target.src;
console.log(src);
$("#showcase-book-img").fadeOut(function() {
$(this).on('load', function() {
$(this).fadeIn();
});
$(this).attr("src", src);
});
//record which thumb was clicked
$("#book-list li").removeClass("active"); //remove class
$(this).addClass("active"); //apply class to selected thumb
});
//move next
$("#left-arrow").click(function() {
if ($("#book-list li.active").next("#book-list li").length > 0) {
$("#book-list li.active").next().children('img').trigger("click");
} else {
$("#book-list li:first > img").trigger("click"); //go to first
}
return false;
});
//move previous
$("#right-arrow").click(function() {
if ($("#book-list li.active").prev("#book-list li").length > 0) {
$("#book-list li.active").prev().children('img').trigger("click");
} else {
$("#book-list li:last > img").trigger("click"); //go to end
}
return false;
});
$('#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) {
$('.book').each(function(key) {
var numKey = key + 1;
if (userInput == numKey) {
// console.log(numKey + " success");
var currentKey = userInput;
var scrollPos = $('#book-list li:nth-child(' + currentKey + ')').children('img').trigger('click').scrollLeft();
$('#book-list').scrollLeft(scrollPos);
// $(window).scrollLeft($('#book-list li:nth-child('+ currentKey +').children('img').trigger('click')');
}
})
return false; // prevent the button click from happening
}
});
//click the first thumb to begin
$("#book-list li:first...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.