Keep tooltip opened when the mouse is over it

故事扮演 提交于 2021-02-08 11:27:28

问题


I want to create a simple tooltip using jquery. When the user hovers some link a small box should appear next to it with some dynamic content. The only thing I can't figure out it is how to keep the tooltip opened when the mouse is over the tooltip itself? If the mouse is out of the link the tooltip should be closed automatically, except when the mouse is over the tooltip itself, because there will be some links in the tooltip and users should be able to click it...

Can anyone please point out how this can be done using jquery?


回答1:


If you just want get it working, use one of dedicated plugins, e.g. qtip.

If you, for some reason, want or have to do it yourself, here's how I did it.
You do not close tooltip immediately when mouse leaves link, but setup setTimout close handler. If in, say, 0.5 seconds mouse returns over tooltip or link, you cancel handler. To do that, you can store timeout id (retured by setTimeout) as jquery data object associated with tooltip.




回答2:


Update: Its much better to use jQuery UI tooltip as of now.
URL: http://jqueryui.com/tooltip/


Rather than writing your own Tooltip use any of the jQuery Tooltip plugins available.

simpletip is a good one I had been using previously.

$("jquery selector").simpletip({
   fixed: true
});



回答3:


If there is no space between link and tooltip, simply let the tooltip be the child node of the link and use mouseenter and mouseleave events on the link.




回答4:


Try this one: jQuery Tooltip Plugin



来源:https://stackoverflow.com/questions/4933062/keep-tooltip-opened-when-the-mouse-is-over-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!