jQuery UI Tooltip加载并显示延迟

Zhi*_*ago 3 html css jquery jquery-ui tooltip

该网站包含带有动态内容的工具提示的链接.我正在使用jquery UI Tooltip来显示它们.我不希望每次用户意外地将光标悬停在显示工具提示的链接上.我只想在显示工具提示时将光标延迟链接几秒钟.它应该像在Gmail中一样工作,当您将鼠标悬停在发件人名称上时,您会看到有关他的信息(参见图片).

我需要工具提示,用户可以与之交互,所以我使用此代码(感谢Antonimo /sf/answers/1051033161/)

$( document ).tooltip({
  show: null, // show immediately 
  items: 'input',
  hide: {
    effect: "", // fadeOut
  },
  open: function( event, ui ) {
    ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" );
  },
  close: function( event, ui ) {
    ui.tooltip.hover(
        function () {
            $(this).stop(true).fadeTo(400, 1); 
            //.fadeIn("slow"); // doesn't work because of stop()
        },
        function () {
            $(this).fadeOut("400", function(){ $(this).remove(); })
        }
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

这里的示例(当鼠标悬停在带有工具提示的元素上时,您可以看到所有这些混乱)

怎么做得更好?使用timeOut?或者也许我应该使用hoverIntent插件?但它将如何编码?

Tre*_*vor 7

这是一种方法:

HTML

<body>
    <p><label for="age">Your age:</label><input class="age" id="age" /></p>
    <p><label for="age">Your age:</label><input class="age" id="age2" /></p>
    <p><label for="age">Your age:</label><input class="age" id="age3"/></p>
    <p><label for="age">Your age:</label><input class="age" id="age4"/></p>
    <p><label for="age">Your age:</label><input class="age" id="age5"/></p>
</body>
Run Code Online (Sandbox Code Playgroud)

jQuery的

var timeout;
var finishTimeout = false;
$(".age").tooltip({
  show: null, // show immediately 
  items: 'input',
  hide: {
    effect: "", // fadeOut
  },
     content: function(){
         if(!finishTimeout)
             return false;
         //ajax call here 
         return 'test';
     },
  open: function( event, ui ) {
    //ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" );
  },
  close: function( event, ui ) {
    ui.tooltip.hover(
        function () {
            $(this).stop(true).fadeTo(400, 1); 
            //.fadeIn("slow"); // doesn't work because of stop()
        },
        function () {
            $(this).fadeOut("400", function(){ $(this).remove(); })
        }
    );
  }
});
$('.age').mouseover(function(){
   var el = $(this);
    timeout = setTimeout(function(){
       finishTimeout = true;
       el.tooltip( "open" );
       finishTimeout = false;
    },1000);
});
$('.age').mouseout(function(){
    clearTimeout(timeout);
});
Run Code Online (Sandbox Code Playgroud)

示例 http://jsfiddle.net/4sSkc/