Gallery按钮未更新为要关联的当前图像

Gallery button not updating to current image it is meant to be associated with?

本文关键字:图像 关联 按钮 更新 Gallery      更新时间:2023-09-26

好的,我做了一个图库,除了一件事,它还可以工作如果在播放动画时单击导航按钮,则导航按钮将显示错误的高亮显示按钮,直到图像发生变化这里有一个问题的例子:

http://puu.sh/gQkuv/600e32fa0d.mp4这是js代码和JS小提琴:

  // gallery buttons
  $('.navi > img').click(function() {
    var sync = $(this).index();
    sync *= -galleryWidth;
    clearInterval(gallery);
    $('.pics > img').animate({'left': sync});
    $('.navi > img').removeClass('active');
    $('.navi > img:nth-of-type(' + ($(this).index() + 1) + ')').addClass('active');
    gallery = setInterval(autoplay(sync), 5000);
  });
  // gallery start loop
  var gallery = setInterval(autoplay(current), 5000);

http://jsfiddle.net/pa8pqnLw/2/

对不起,这个解释不太好,但有人能不能试着指出问题所在,并提供可能的解决方案。提前谢谢。

问题是你的自动播放在动画完成后设置点,当你点击时,它会立即设置点,然后它会被自动播放的完整功能覆盖

单击时需要停止动画。我只是通过添加.stop() 在导航点击处理程序中编辑了这一行

$('.pics > img').stop().animate({'left': sync});

http://jsfiddle.net/pa8pqnLw/4/

更多信息请点击此处https://api.jquery.com/stop/

描述:停止匹配的上当前正在运行的动画元素。