我用jquery来计算是
var currentPosition = 0;
var slides = $(".slideritem");
var numberOfSlides = slides.length;
manageControls(currentPosition);
function manageControls(position){
var count = document.getElementById("count");
count.innerHTML =(position + 1) + "/" + numberOfSlides;
}
这是我的JSFiddle。它显示计数但是当我进入下一个div时它不会更新。任何解决方案?
答案 0 :(得分:1)
您错过了对manageControls()
的通话...您可以将其放在此处:
$('li').click(function() {
var index = $(this).index();
setActive(index);
manageControls(index);
});
答案 1 :(得分:0)
var currentPosition = 0;
var slides = $(".myclass");
var numberOfSlides = slides.length;
manageControls(currentPosition);
function manageControls(position){
var count = document.getElementById("count");
count.innerHTML =(position + 1) + "/" + numberOfSlides;
}
setActive(0);
$('li').click(function() {
setActive($(this).index());
manageControls($(this).index());
});
$(".next").click(function(){
var current = $('ul li.selected').index(),
maxIndex = $('ul li').length - 1,
next = (current + 1) > maxIndex ? 0 : (current + 1);
manageControls(next);
setActive(next);
});
function setActive(i) {
var li = $('ul li').eq(i);
$('ul li').removeClass('selected');
li.addClass('selected');
$('.myclass').removeClass('selected');
$('.myclass').eq(i).addClass('selected');
}