开发者

Building a tooltip feature from scratch in jQuery

开发者 https://www.devze.com 2023-03-14 03:59 出处:网络
I want a very dynamic and simple tool-tip feature in my web app (very much like Facebook\'s). I have looked around at all the jQuery开发者_运维技巧 plugins but don\'t fancy them really, so want to bui

I want a very dynamic and simple tool-tip feature in my web app (very much like Facebook's). I have looked around at all the jQuery开发者_运维技巧 plugins but don't fancy them really, so want to build my own. It needs to be able to display lists as well as single items on hover of certain html elements.

My main question is that is it best to build the html tooltip element in jQuery and then insert into the DOM every time a relevant element is hovered, or have one tool-tip to serve all tool-tip hover activity and just move it around and change the content inside it?

Any tool-tip experience would be of interest!


Well.. You have 2 options:
1) Generate a tooltip every time you need to show it, but don't forget to remove it from DOM, after hide.
2) But IMHO best way is to initialize tooltip only once, and then just position it at right place, modifying its contents.


Try tipsy tooltip jquery plugin

http://fishintheriver.com/2009/03/04/a-cool-facebook-style-tooltip-plugin-for-jquery/

But if you wanna do it by yourself then i think 2nd option is good "have one tool-tip to serve all tool-tip hover activity and just move it around and change the content inside it"


I ended up constructing and removing a new tooltip instance on each mouseenter/mouseleave. Works really well!

0

精彩评论

暂无评论...
验证码 换一张
取 消