开发者

Cancel hoverIntent timer

开发者 https://www.devze.com 2023-02-06 04:26 出处:网络
I\'ve used jQuery and hoverIntent plugin many times, for dropdown menus and advanced navigation that should be a bit more elegant. But I\'ve run into a problem.

I've used jQuery and hoverIntent plugin many times, for dropdown menus and advanced navigation that should be a bit more elegant. But I've run into a problem.

I have a menu with a clickable li element that also has a hover. If someone clicks it before the intent timer triggers I want to cancel the hoverintent, just because it looks nicer.

I can't figure out how though, designer first, coder second. This is what calls th开发者_开发技巧e intent:

$('#navigationContainer ul li').hoverIntent(configDown);

It's got a variable configDown that defines sensitivity etc. And two functions called slideUp and slideDown. Everything works perfectly.

If someone clicks this same element, I want to cancel the hoverIntent. Any help would be appreciated.


Rather than cancel the hoverIntent, modify the code within the hoverIntent callbacks to first check if the li is clicked:

var configDown = {
    slideUp: function () {
        if ($(this).hasClass('no-intent')) return;
        // slide up
    },
    slideDown: function () {
        if ($(this).hasClass('no-intent')) return;
        // slide down
    }
};

$('#navigationContainer ul li').click(function () {
    $(this).addClass('no-intent');
}).hoverIntent(configDown);

Unless you have a good delay on the hoverIntent though, it may be tricky to trigger this correctly (you might end up clicking just after the hoverIntent is triggered), but the basic idea is there for you to tweak.

0

精彩评论

暂无评论...
验证码 换一张
取 消