【问题标题】:jquery anchoring content to certain pointjquery将内容锚定到某个点
【发布时间】:2011-07-27 13:18:11
【问题描述】:

我的网站上有一个链接列表,当用户点击一个链接时,我会显示一个带有更多选项的工具栏,链接显示为 90x60 图像,我希望显示的工具提示能够自行锚定到已单击的链接/图像的左上角如何实现这一点,下面是我当前的实现。

$('#wrapper #content ul li a').click(function(e) {
    e.preventDefault();
    $('#tooltip').remove();
    var url = $(this).attr('href');
    $.ajax({
        type: "POST",
        url: url,
        data: "",
          success: function(html){
           var popup = html;
           $('#content').append(popup);
           $('#tooltip').css({
             position: "absolute",
             top: e.pageY - 200,
             left: e.pageX - 10
           });
          }
    });
});

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript jquery html css dom-manipulation


    【解决方案1】:

    已经有 jquery 插件:http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/

    还有更多http://visionwidget.com/inspiration/web/495-jquery-tooltip-plugins.html

    或者你可以写一些简单的 jQ 脚本:

    (HTML)

    <div class="tooltipped box"></div>
    <div class="tooltipped box"></div>
    

    (JS)

    $(document).ready(function() {
        $('.tooltipped').click(function(){
            $('#tooltip').remove();
            $('body').append('<div id="tooltip" class="tooltip">This is tooltip</div>');
            var p = $(this).position();
            $('#tooltip').css({top: p.top, left: p.left+$(this).width()});
        });
    });
    

    (CSS)

    .box { border: 1px solid green; width: 90px; height: 60px; }
    .tooltip { border: 1px solid red; width: 50px; height: 50px; position: absolute; }
    

    【讨论】:

      【解决方案2】:

      使用 qTip。

         $(document).ready(function() {
      
      
                 $("#qtip").qtip({
                  content: 'ToolTip',
                  style: {
                      name: 'red'
                  },
                  show: 'mousedown',
                  hide: 'mouseout',
                  position: {
                      target: 'mouse',
                      adjust: {
                          mouse: true,
                          x: -180,
                          y: -30,
                      }
                  }
              });
      
      
      });
      

      更新:这是我的JsFiddle

      【讨论】:

        猜你喜欢
        • 2014-10-10
        • 1970-01-01
        • 2021-12-06
        • 1970-01-01
        • 2012-03-06
        • 2012-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多