JQuery设置间隔和点击功能的困境
以下脚本每 5000 毫秒或单击时触发更改图像。
它使用 .next() 计算出自动超时时要单击的下一个缩略图。问题是,当用户单击缩略图时,自动功能会在 5000 毫秒后正确启动,但 next() 不会根据用户单击进行更新,并且显示的图像不是下一张图像,而是下一张图像如果用户没有点击。
var slideShowTO;
$('#coursepanel .thumbstrip img').click(function(){
$('#coursepanel .thumbstrip img').removeClass('active')
$(this).addClass('active');
var img = '#P' + $(this).attr('id');
$('#coursepanel .gallery .feature img').removeClass('focus');
$(img).addClass('focus');
window.clearInterval(slideShowTO);
slideShowTO = window.setInterval(function(){
if($(this).attr('id') == $('#coursepanel .thumbstrip img:last').attr('id'))
{
$('#coursepanel .thumbstrip img:first').click();
}
else {
$(this).next().click();
}
},5000);
有什么想法吗?
太棒
了#我之前问过这个问题,但由于某种原因,之前的答案不适用于我们现在拥有的非常相似的脚本。
The following script triggers changes an image every 5000ms or on click.
It users .next() to work out the next thumbnail to click when automatically timing out. The problem is that when the user clicks on a thumbnail the automatic function correctly kicks in after 5000ms, but the next() is not updated based on the users click and the image displayed is not the next image but what would have been the next one if the user had not clicked.
var slideShowTO;
$('#coursepanel .thumbstrip img').click(function(){
$('#coursepanel .thumbstrip img').removeClass('active')
$(this).addClass('active');
var img = '#P' + $(this).attr('id');
$('#coursepanel .gallery .feature img').removeClass('focus');
$(img).addClass('focus');
window.clearInterval(slideShowTO);
slideShowTO = window.setInterval(function(){
if($(this).attr('id') == $('#coursepanel .thumbstrip img:last').attr('id'))
{
$('#coursepanel .thumbstrip img:first').click();
}
else {
$(this).next().click();
}
},5000);
Any ideas?
Marvellous
NB# I have asked this question before but for some reason the answer from before is not working with a very similar script we have now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我还留下了另一个优先于这个脚本的脚本。
It would appear I had left another script on too that was taking precedence over this one.