嗨,我正在使用由 http://snook.ca/archives/javascript/simplest-jquery-slideshow 所以基本上我现在的代码是
$(function(){
$('.fadein img:gt(0)').hide();
setInterval(function(){
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');
},
6000);
});
我想知道是否可以获取当前显示的图像的索引?
最佳答案
此脚本的工作方式是不断移动 DOM 元素的位置,以便当前的 img
始终为索引 0,下一个 img
始终为索引 1。如果您想了解原始顺序之外的索引,则需要在幻灯片脚本运行之前存储该数据:
$(function () {
$(".fadein img").each(function (i, el) {
$(el).data('index', i); // Store the index on the IMG
});
$('.fadein img:gt(0)').hide();
setInterval(function(){
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');
// Get the original index of the first img in the current show
alert($('.fadein :first-child').data('index'));
}, 6000);
});
关于jquery - jquery 获取当前索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3778734/