且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有插件的情况下使用jquery创建工具提示?

更新时间:2022-11-03 10:04:34

看看各种 CSS函数在jQuery中,主要是 offset() ,也许还有

Take a look at the various CSS functions in jQuery, mostly offset() and maybe height().

// pseudocode, assuming #tooltip has position: absolute
// do something similar with the left offset as well
$('#tooltip').css({ top : $('#link').offset().top + 10 + 'px' });

这会将工具提示静态地放置在链接之上或附近,我认为这是您想要的.如果要用鼠标移动工具提示,则需要动态更新 mousemove中的位置事件.

This would place the tooltip statically over, or close to, the link, which I think is what you're looking for. If you want the tooltip to move with the mouse, you'll need to dynamically update the position in a mousemove event.