【问题标题】:Adding a delay on mouseout with jquery使用 jquery 添加鼠标悬停延迟
【发布时间】:2016-01-29 01:14:46
【问题描述】:

我正在编写一个函数来触发鼠标悬停/鼠标移出的淡入淡出效果,一切正常,但现在我需要在鼠标移出时添加延迟。 当鼠标悬停在链接上时,相关的 div 必须淡入,而其他的需要淡出。

我试了很多次都没有成功...

代码如下:

function selectedSwitch() {
            $('.selectedSwitch').each(function() {
                $(this).on("mouseover", function(e) {
                    e.preventDefault();
                    var current = $(this).data('selected');
                    $('.selected.post-'+current).stop().animate({'opacity': 1}, 200);
                    $('.selected.post-'+current).siblings().stop().animate({'opacity': 0}, 200);
                });
                $(this).on("mouseout", function(e) {
                    e.preventDefault();
                    var current = $(this).data('selected');
                    $('.selected.post-'+current).stop().animate({'opacity': 0}, 200);
                });
            });
    }

非常感谢!

【问题讨论】:

  • 我不太明白这个问题。您是否要等到第一个动画完成后再做 mouseout 动画?

标签: jquery css


【解决方案1】:

您不能延迟事件的触发,但您可以使用setTimeout 函数在执行的代码中添加延迟

【讨论】:

  • 你是怎么尝试的? setTimeout 是一个函数而不是一个属性.. 例如。 setTimeout(functionName, TimeoutInMilliseconds);在你的事件中添加这个,函数名将在 TimeoutInMilliseconds 过期后被调用。
猜你喜欢
  • 1970-01-01
  • 2011-12-14
  • 2021-08-17
  • 1970-01-01
  • 1970-01-01
  • 2012-03-12
  • 2016-12-20
  • 2010-12-03
  • 2013-01-25
相关资源
最近更新 更多