[英]add delay on hover - menu jquery
My problem is: If you go from 2014 to Dec and the mouse passes over 2015 , then the year changes to 2015.I need to add a small delay so the year stays as 2014 . 我的问题是:如果您从2014年到12月 ,并且鼠标经过2015年 ,则年份更改为2015年。我需要添加一个小的延迟,以使年份保持为2014年 。
here the jsfiddle demo demo link Note: hover on Past Events
. 这里是jsfiddle演示演示链接注:将鼠标悬停在Past Events
。
$(".dropdown-menu > li > a.trigger").on("mouseover",function(e){
var current=$('.dropdown-menu > li > a.trigger').next();
var grandparent=$('.dropdown-menu > li > a.trigger').parent().parent();
if($('.dropdown-menu > li > a.trigger').hasClass('left-caret')||$('.dropdown-menu > li > a.trigger').hasClass('right-caret'))
$('.dropdown-menu > li > a.trigger').toggleClass('right-caret left-caret');
grandparent.find('.left-caret').toggleClass('right-caret left-caret');
grandparent.find(".sub-menu:visible").hide();
current.fadeIn(200);
e.stopPropagation();
});
Try something along these lines. 尝试以下方法。
var selected = null;
var queued = null;
$(".dropdown-menu > li > a.trigger").on("mouseover", function (e) {
if (selected !== this) {
addQueue(this);
} else {
// the rest of your code!
}
});
function addQueue($el) {
queued = $el;
setTimeout(function () {
if (queued === $el) {
selected = $el;
$el.trigger('mouseover');
}
}, 500);
}
The easiest implementation may be to use a jQuery plugin called HoverIntent 最简单的实现可能是使用名为HoverIntent的jQuery插件
http://cherne.net/brian/resources/jquery.hoverIntent.html http://cherne.net/brian/resources/jquery.hoverIntent.html
Your JS would just be: 您的JS就是:
$(".dropdown-menu > li > a.trigger").hoverIntent(function(e){
// Do Stuff...
});
This way, the listener would only fire when the user hovers over the element for long enough at a slow enough mouse speed. 这样,仅当用户以足够慢的鼠标速度将鼠标悬停在元素上足够长的时间时,侦听器才会触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.