Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery mouseleave上的停止功能_Jquery_Foreach_Mouseleave - Fatal编程技术网

Jquery mouseleave上的停止功能

Jquery mouseleave上的停止功能,jquery,foreach,mouseleave,Jquery,Foreach,Mouseleave,我对mouseenter上的触发器和它的循环有问题。问题是我想在mouseleave上停止运行 尝试了几件事,但似乎没有任何效果 HTML 链接到我的笔: 您只需清除设置超时,如下所示 不过请注意,根据是否要再次隐藏文本,这取决于您自己,因此请相应地进行处理 let timeoutFunc; function highlight(items, index) { index = index % items.length; items.removeClass(&qu

我对mouseenter上的触发器和它的循环有问题。问题是我想在mouseleave上停止运行

尝试了几件事,但似乎没有任何效果

HTML

链接到我的笔:

  • 您只需清除
    设置超时
    ,如下所示

  • 不过请注意,根据是否要再次隐藏文本,这取决于您自己,因此请相应地进行处理

      let timeoutFunc;
      function highlight(items, index) {
          index = index % items.length;
          items.removeClass("-visible");
          items.eq(index).addClass('-visible');   
          timeoutFunc = setTimeout(function() {
              highlight(items, index + 1)
          }, 1000);
      }
    
      $( ".trigger" ).mouseenter(function() {
          highlight($('.logo-tagline span'), 0);
      });
    
      $( ".trigger" ).mouseleave(function() {
          $('.-visible').removeClass("-visible");
          clearTimeout(timeoutFunc);
      });
    

检查此工作示例:


你能帮我去掉mouseleave上的“-visible”类吗?非常感谢!
$( ".trigger" ).mouseenter(function() {
  function highlight(items, index) {
    index = index % items.length;
    items.removeClass("-visible");
    items.eq(index).addClass('-visible');   
    setTimeout(function() {
      highlight(items, index + 1)
    }, 1000);
  }
  
  highlight($('.logo-tagline span'), 0);
});


  let timeoutFunc;
  function highlight(items, index) {
      index = index % items.length;
      items.removeClass("-visible");
      items.eq(index).addClass('-visible');   
      timeoutFunc = setTimeout(function() {
          highlight(items, index + 1)
      }, 1000);
  }

  $( ".trigger" ).mouseenter(function() {
      highlight($('.logo-tagline span'), 0);
  });

  $( ".trigger" ).mouseleave(function() {
      $('.-visible').removeClass("-visible");
      clearTimeout(timeoutFunc);
  });
$( ".trigger" ).mouseenter(startInterval);
$( ".trigger" ).mouseleave(stopInterval);

// You'll need a variable to store a reference to the timer
var timer = null;

function startInterval() {

  /* Your Function Code HERE */

  // Then you initilize the variable
  timer = setInterval(function() {
    console.log("Foo Executed!");
  }, 1500);
}

function stopInterval() {
  // To cancel an interval, pass the timer to clearInterval()
  clearInterval(timer);
}