Adding delay to jquery event on mouseover

你离开我真会死。 提交于 2019-12-05 16:40:19
Nick Craver

You need to define what this is when it executes, something like this would work:

setTimeout($.proxy(function() { $(this).children(".skinnyPopup").show(); }, this), 600)

Or just use .delay(), like this:

$(this).children(".skinnyPopup").delay(600).show(0);

Both of the above are quick fixes, I suggest you move away from inline handlers and check out an unobtrusive method (see this answer by Russ Cam for some great reasons), for example:

$(function() {
  $('selector').mouseover(function() {
    $(this).children(".skinnyPopup").delay(600).show(0);
  });
});

It's because this is bound to the global context, not the element. Use something like the following instead:

// put this in your document head -- replace element with a selector for the elements you want
$(function () {
    $(element).bind("mouseover", function () {
       var e = $(this);
       setTimeout(function () { e.children(".skinnyPopup").show(); }, 600);
    });
});

If you're adamant about inline event handlers, the following should also work:

onmouseover='var self = this; setTimeout(function() { $(self).children(\".skinnyPopup\").show(); }, 600)'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!