Simple image slider using JQuery
following is the jquery code for image slider
function showImage() {
var shopImages = sessionStorage.getItem('shopImages'); // comma separated image paths
shopImage = shopImages.split(',');
$('#bg').css('background', 'url(' + shopImage[0] + ')'); // by default first image will be back ground image
$('#ImageCount').text("1/" + shopImage.length);// show current image
var step = 1;
var current = 1;
var maximum = shopImage.length;// maximum length of Image collection
var visible = 2;
var speed = 200;
// right click increments
$('#right').click(function () {
if (current + step <= maximum) {
current = current + step;
$('#bg').css('background', 'url(' + shopImage[current - 1] + ')');
$('#ImageCount').text(current + "/" + shopImage.length);
}
});
// left click decreases
$('#left').click(function () {
if (current == 1) {
$('#bg').css('background', 'url(' + shopImage[0] + ')');
$('#ImageCount').text( "1/" + shopImage.length);
}
if (current >1 && current> current - step) {
current = current - step;
$('#bg').css('background', 'url(' + shopImage[current-1] + ')');
$('#ImageCount').text(current + "/" + shopImage.length);
}
});
}
Comments