跟随鼠标的 Jquery 工具提示

标签 jquery html jquery-plugins

我只想让鼠标悬停在 div 上时跟随鼠标的工具提示。我想用这个:

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

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

最佳答案

我找到了 this在他们的网站上。

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

<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>

如果我是您,您可以制作自己的工具提示,但这取决于您想要什么。

更新

三年后... 当然,现在您应该添加 debouncethrottle

关于跟随鼠标的 Jquery 工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4582625/

相关文章:

javascript - 数组元素的 child

javascript - 如何禁用 HTML 表格的所有行?

javascript - 在 Fullcalendar.js 中显示事件时出现问题

javascript - 如何使用多个 jquery 版本以便 ResponsiveSlides.js 工作?

javascript - 如何使用 jQuery 定期更新页面上的日期/时间值?

php - 如果 WooCommerce 购物车中有特定产品,则强制输入 "Ship to different address"

javascript - Browserify:防止在同一个应用程序中多次包含同一个 npm-module

javascript - 在 IE 8 的 javascript 中启用/禁用下拉值

javascript - 如何从字符串创建 URL 链接

css - 使用数字导航调整简易 slider 1.7 版的宽度和高度