【发布时间】:2013-10-30 17:54:20
【问题描述】:
我在 jQuery 中构建了一个小型幻灯片。这很简单。如何在页面加载时自动启动滑块?滑块应该一直运行。只有当用户点击我的缩略图时,滑块才会直接跳转到该幻灯片。
var totalWidth = 0;
var positions = new Array();
$('.slides .slide').each(function (i) {
positions[i] = totalWidth;
totalWidth += $(this).width();
});
$('.slides').width(totalWidth);
$('.slideMenu ul li a').click(function (e) {
var pos = $(this).parent().prevAll('.menuItem').length;
$('.slides').stop().animate({
marginLeft: -positions[pos] + 'px'
}, 450);
e.preventDefault();
});
【问题讨论】:
-
请在问题中包含您的代码。 jsfiddle 很棒,但如果网站出现故障,您的问题将无法回答。