[英]Lightbox image slider is not coming click wise and slider is not looping properly
In my code i have three images and when each image is clicked a modal box will open and that box will have a function to show all images by clicking right arrow(next), left arrow(prev). 在我的代码中,我有三个图像,当单击每个图像时,将打开一个模式框,该框将具有通过单击右箭头(下一个),左箭头(上一个)来显示所有图像的功能。
I've done all basic things but I am facing two problems: 我已经完成了所有基本工作,但是面临两个问题:
This is my JavaScript code: 这是我的JavaScript代码:
//next prev images
//active image setting
$('.image_post li:first').addClass('activepostimg');
//code for next image
$('.buttons_next').on('click', function() {
$('.image_post li.activepostimg').index() + parseInt(1) !== $('.image_post li').length ;
$('.activepostimg').removeClass('activepostimg').next('.image_post li').addClass('activepostimg');
});
//code for previous
$('.buttons_prev').on('click', function() {
$('.image_post li.activepostimg').index() + parseInt(1) !== $('.image_post li').length ;
$('.activepostimg').removeClass('activepostimg').prev('.image_post li').addClass('activepostimg');
});
//Image counter
var totalItems = $('.image_post li').length;
var currentIndex = $('.activepostimg').index() + 1;
$('.slide_image_counter a').html(''+currentIndex+'/'+totalItems+'');
//for next
Replace all your js code and remove class="activepostimg"
from your html. 替换所有的js代码,并从HTML中删除class="activepostimg"
。 Here is the DEMO 这是演示
Make sure that your images are in the same order when they are zoomed and not. 确保图像缩放时的顺序相同,而不要缩放。
var totalItems = $('.image_post li').length, currentIndex = 1;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
//code for opening image
$('.grid img').on('click', function() {
currentIndex = $('.grid img').index(this) + 1;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
$(".image_post li").removeClass("activepostimg");
$('.image_post li').eq(currentIndex - 1).addClass('activepostimg')
});
//code for next image
$('.buttons_next').on('click', function() {
if($('.image_post li.activepostimg').index() < ($('.image_post li').length - 1)){
currentIndex++;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
$('.activepostimg').removeClass('activepostimg').next('.image_post li').addClass('activepostimg');
} else {
currentIndex = 1;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
$(".image_post li").removeClass("activepostimg");
$('.image_post li').eq(currentIndex - 1).addClass('activepostimg')
}
});
//code for previous
$('.buttons_prev').on('click', function() {
if ($('.image_post li.activepostimg').index() > 0) {
currentIndex--;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
$('.activepostimg').removeClass('activepostimg').prev('.image_post li').addClass('activepostimg');
} else {
currentIndex = $('.image_post li').length;
$('.slide_image_counter a').html('' + currentIndex + '/' + totalItems + '');
$(".image_post li").removeClass("activepostimg");
$('.image_post li').eq(currentIndex - 1).addClass('activepostimg')
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.