简体   繁体   English

结合jquery cluetip和hoverintent?

[英]Combining jquery cluetip and hoverintent?

I'm using jquery's cluetip to show, huh, tooltips :-) I made them sticky, because I want the user to be able to move the mouse to the shown tooltip - if they wish. 我正在使用jquery的cluetip来显示,呵呵,工具提示:-)我让它们变得粘稠,因为我希望用户能够将鼠标移动到显示的工具提示 - 如果他们愿意的话。 However, if the user does not move the mouse to the tooltip, I want the tooltip to disappear after some time. 但是,如果用户没有将鼠标移动到工具提示,我希望工具提示在一段时间后消失。 It seems to me, that this should be possible using the hoverintent-plugin. 在我看来,这应该可以使用hoverintent-plugin。 But this plugin does not fire unless the user moves the mouse over the plugin once. 但是,除非用户将鼠标移到插件上一次,否则此插件不会触发。 If that happens, cluetip removes the tooltip by itself... 如果发生这种情况,cluetip会自动删除工具提示......

How can I get a tooltip to display, wait for 500 msec, and if the user does not mouseover the tooltip, than disappear? 如何显示工具提示,等待500毫秒,如果用户没有鼠标悬停工具提示,则消失?

I've been thinking about fireing a timer with onShow, adding a script to the tooltip that onmouseover disables the timer and stuff like that, but that seems overly complicated... 我一直在考虑使用onShow触发计时器,在工具提示中添加一个脚本,onmouseover禁用计时器和类似的东西,但这似乎过于复杂......

Anybody got a better idea? 有人有更好的主意吗? :-) :-)

Thanks, 谢谢,

Paul 保罗

I don't know a tooltip plugin that supports that, so you may have to create something yourself. 我不知道支持它的工具提示插件,所以你可能必须自己创建一些东西。 The following example works, although making it generic, reusable and use a tooltip plugin will require more work. 以下示例有效,虽然使其通用,可重用并使用工具提示插件将需要更多工作。

<a href="#" onclick="activateTip()">click here</a>
<div id="tooltip" style="background: green; height: 30px; width: 50px; color: white;
   display: none; position: absolute">
   fake tooltip
</div>
<script type="text/javascript">

    function activateTip() {
       $("#tooltip").fadeIn(autoFade);
    }

    function autoFade() {
       var cancel = setTimeout(hideTip, 3000);
       $("#tooltip").mouseover(function () {
          clearTimeout(cancel);
          $("#tooltip").unbind("mouseover").mouseout(autoFade);
       });
    }

    function hideTip() {
       $("#tooltip").fadeOut().unbind("mouseover").unbind("mouseout");
    }

</script>

The question was if it is possible to "Combine jquery cluetip and hoverintent?". 问题是,是否可以“结合jquery cluetip和hoverintent?”。 The simple anwser is: yes. 简单的anwser是:是的。

Simply download and include the HoverIntent script on your page. 只需下载并在页面上包含HoverIntent脚本即可。 The script (+ examples) can be found at: http://cherne.net/brian/resources/jquery.hoverIntent.html 脚本(+示例)可以在以下网址找到: http//cherne.net/brian/resources/jquery.hoverIntent.html

When you've included HoverIntent, you can set some additional options for your 'ClueTip': 当您包含HoverIntent时,您可以为“ClueTip”设置一些其他选项:

$basketTooltips.cluetip({
    attribute:        'rel',

        // other options        

    // HoverIntent specific options
    hoverIntent: {
        sensitivity:  3,
        interval:     100,
        timeout:     500
    },

});

The cluetip HoverIntent options are equal to the original HoverIntent options, found at: http://cherne.net/brian/resources/jquery.hoverIntent.html cluetip HoverIntent选项等于原始HoverIntent选项,位于: http ://cherne.net/brian/resources/jquery.hoverIntent.html

I use this lib with some customizations. 我使用这个 lib与一些自定义。 You can replace line 77 您可以替换第77行

$tooltipC.html($tooltip.data("title"));

of this file with the following line: 文件的行如下:

$tooltipC.html(options.content);

And than you can use it as follows: 而且你可以使用它如下:

$('.tooltip-target').each(function () {
        $(this).tooltip({
            cssClass: "tooltip",
            content: $($(this).attr("rel")).html()
        });
    });

As you can see in my project for every tooltip target I set attribute rel with the selector of control with html for tootlip. 正如您在我的项目中可以看到的每个工具提示目标一样,我使用带有html for tolip的控件选择器设置属性rel。 As follows: 如下:

<img src="help.ico" class="tooltip-target" rel="#helpTooltip" />
<div style="display:none" id="helpTooltip">
    Some html content for tooltip
    <a href="help.html">Details..</a>
</div>

You can use the following method to do it. 您可以使用以下方法执行此操作。

JQuery: JQuery的:

//Change it to your tooltip object- ID/Name/Class
$("#tooltip").mouseout(function(){
  $(this).delay(500).queue(function() {
    $(this).css('display', 'none');
  });
//We use this method because, user can come over the element before its disapper.
}).mouseover(function() {
   if($(this).is(':visible'))
     $(this).css('display', '');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM