簡體   English   中英

setTimeout不起作用?

[英]setTimeout not working?

我正在嘗試在衰落元素上設置超時,以便在再次淡入/淡出之前有一點緩沖。 由於某些原因,我的setTimeout函數似乎無法正常工作。 我以前遇到過這種麻煩,我真的很想知道為什么。

這是我目前正在使用的:

var button_timer;
    if (fade_in_but_hover != "none" && fade_out_but_hover != "none") {
        $(".first-level-items > .li").hover(function() {
            clearTimeout(button_timer);
            $(this).find("a").first().animate({ color: font_color_hover }, fade_in_but_hover);
        }).mouseleave(function() {
            button_timer = setTimeout(function() {
                $(this).find("a").first().animate({ color: font_color }, fade_out_but_hover);
            }, 1000);
        });
    }

您需要范圍this

  }).mouseleave(function () {
      var $this = $(this);//here
      setTimeout(function () {
          //use $this here
          $this.find("a").first().animate({
              color: font_color
          }, fade_out_but_hover);
      }, 1000);
  });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM