跟随鼠标的Jquery工具提示

Gui*_*889 3 html jquery jquery-plugins

我想简单地在鼠标悬停在div上时有一个跟随鼠标的工具提示.我想用这个:

http://flowplayer.org/tools/tooltip/

我让它工作,但是当鼠标指针移动时我无法获得实际跟随鼠标的工具提示.我知道这听起来像愚蠢的问题,但他们的网站没有任何这个功能的演示,所以我想知道它是否支持.有谁知道如何使这项工作?感谢您的投入和时间!

Yor*_*gen 9

我在他们的网站上找到了这个.

我会做自己的..只是为了帮助你一点点:

<style>
    .item {
        position: relative;
        width: 100px;
        height: 40px;
        top: 200px;
        left: 400px;
        background: #CCC;
    }

    .item .tooltip {
        position: fixed; /** depends on how it handles the e.pageX and e.pageY **/
        width: 80px;
        height: 30px;
        background: #06F;
        z-index: 10;
        display: none; /**let the tooltip be not visable, when startup **/
    }
</style>

<script type="text/javascript">
    $(document).ready(function() {
       $(".item").mousemove(function(e) { 
            // put other effects in when moving over the element
            // from e you can get the pageX(left position) and pageY(top position) 
            // im not sure if it was the relative or the absolute position
            // i added 10 pxs on the top and left to show the tooltip a bit after
            $('.tooltip').css('left', e.pageX + 10)
                .css('top', e.pageY + 10)
                .css('display', 'block');

            // or in a simpler way:
            $('.tooltip').css({
                left: e.pageX + 10,
                top: e.pageY + 10
            }).css('display', 'block');
        });

        $(".item").mouseout(function() { 
            $('.tooltip').css('display', 'none');
        });
    });
</script>

<div class="item">
    <p>This is my item</p>
    <div class="tooltip">Tooltip</div>
</div>
Run Code Online (Sandbox Code Playgroud)

如果我是你自己的工具提示,但这取决于你想要的.

UPDATE

3年后...当然,现在你应该加一个debouncethrottle.


whj*_*jou 5

wrt http://flowplayer.org/tools/demos/tooltip/dynamic.htm,试试吧

// initialize tooltip
$("#dyna img[title]").tooltip({

   // tweak the position
   offset: [10, 2],

   // use the "slide" effect
   effect: 'slide'

// add dynamic plugin with optional configuration for bottom edge
}).dynamic({ bottom: { direction: 'down', bounce: true } })

// Additional code : BEGIN
.mousemove(function(evt) {$(".tooltip").css({
    left:(evt.pageX - $.tools.tooltip.conf.offset[1]),
    top:(evt.pageY - $.tools.tooltip.conf.offset[0])
});})
// Additional code : END

;
Run Code Online (Sandbox Code Playgroud)

请自己调整定位.:)