jquery工具提示mouseout mouseover

时间:2011-08-11 20:36:39

标签: javascript jquery

我遇到了问题。以下工具提示工作得很好,但有一个问题。当我将鼠标移到右侧时,光标比工具提示更快并将其悬停。这将隐藏并显示分段秒的Cursor。

http://gabibyte.zxq.net/jquery_tooltips/example.html
// !REMEMBER TO INCLUDE JQUERY IN YOUR PAGE - IF YOU DON'T KNOW HOW, JUST INCLUDE THE LINE OF CODE BELOW IN THE <HEAD>...</HEAD> PART OF YOUR PAGE
/* <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script> */
//----------------------------------------------CONFIGURATION
var offset=15; //Distance between tooltip and cursor
var fadeInSpeed=600; //Speed of the Fade-IN effect in miliseconds
var fadeOutSpeed=200; //Speed of the Fade-OUT effect in miliseconds
var clearQueue = true; //If set to false, if you hover over many elements fast, the events will stack up
var gotoEnd= true; //If set to false, if you hover over many elements fast, the events will stack up
//---------------------------------------------GLOBAL VARIABLES
var mouseX,mouseY; 
$(document).ready(function(){
//-----------------------------------------------MOUSE EVENTS
  $(document).mousemove(function(e){
     mouseX=e.pageX+offset;
     mouseY=e.pageY;+offset
     $('.floating').css('top',mouseY);
     $('.floating').css('left',mouseX);
  });
//------------------------------------------------HOVER EVENTS
$('.hastooltip').hover(function () {
    var selector ="#"+ $(this).attr('tooltip');
    //alert(selector);
    //$(selector).stop(clearQueue , gotoEnd) 
    $(selector).fadeIn(250,function () {});
},function () {
    var selector ="#"+ $(this).attr('tooltip');
    $(selector).fadeOut(fadeOutSpeed,function () {});

    }
);
});

对于onmouseout,有没有办法说“如果悬停工具箱什么也不做fadeOut”。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您可以将.setTimeout()用于悬停时想要发生的事情。然后将鼠标悬停在工具提示中,取消该超时(使用.clearTimeout())。您可能希望元素上的setTimeout / clearTimeout相同,并且工具提示悬停offs / ons(分别),这样如果有人将鼠标返回到其中任何一个,则不会发生悬停。

因此,如果你有2秒的超时,当有人徘徊时,计时器将启动,但只要有人在2秒内从元素悬停到工具提示,它就会被取消。