jQuery文本行情指示器在悬停时暂停

我找到了此文本信息:http://jsfiddle.net/4mTMw/8/

如何在悬停时暂停文本?

我尝试过:

marquee.hover(function() {
    clearInterval(marquee);
    clearInterval(mar);
    marquee.css('animation-play-state','paused');
    mar.css('animation-play-state','paused');
    marquee.stop();
    mar.stop();
});

什么都没有。

xuelei4460 回答:jQuery文本行情指示器在悬停时暂停

工作示例:https://jsfiddle.net/Twisty/qL93omsj/2/

JavaScript

$(function() {
  var marquee = $('div.marquee');
  marquee.each(function() {
    var mar = $(this),indent = mar.width();
    mar.marquee = function() {
      indent--;
      mar.css('text-indent',indent);
      if (indent < -1 * mar.children('div.marquee-text').width()) {
        indent = mar.width();
      }
    };
    mar.data('interval',setInterval(mar.marquee,1000 / 60));
    mar.hover(function() {
      clearInterval($(this).data("interval"));
    },function() {
      $(this).data('interval',1000 / 60));
    });
  });
});

时间间隔已保存到数据中。您将需要对此使用clearInterval()来暂停它。

本文链接:https://www.f2er.com/2481508.html

大家都在问