繁体   English   中英

jQuery Tooltip UI - x秒后触发工具提示

[英]jQuery Tooltip UI - trigger tooltip after x seconds

这是我到目前为止:

<!DOCTYPE HTML>
<html>
  <head>
    <title>Tooltip Testings</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <style type="text/css"> 
      body { margin: 60px auto; } p { padding:0; margin: 4px auto; text-align: center; }
    </style>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
    <script type="text/javascript">
    $(function() {
      $(document).tooltip({
        items: '.tooltip',
        show: 100,
        hide: 500,
        position: { my: 'center bottom', at: 'center top' },
        content: function( callback ) {
          var msgid = this.id.split('_')[1];
          $.ajax({
            type: 'post',
            url: '/tooltip.php',
            data:'i='+msgid,
            success: function( data ) { callback( data ); }
          });
        }
      });
    });
    </script>
  </head>
  <body>

    <p><a class="tooltip" id="i_283" href="articles/programming-in-php.html">PHP Article</a></p>
    <p><a class="tooltip" id="i_567" href="articles/programming-in-c.html">C+ Article</a></p>
    <p><a class="tooltip" id="i_741" href="articles/programming-in-aspx.html">ASPX Article</a></p>
    <p><a class="tooltip" id="i_860" href="articles/programming-in-java.html">Java Article</a></p>

  </body>
</html>

以上是工作,因为它可以工作,但是,我想只在鼠标悬停链接一段特定时间后(例如2秒)触发工具提示。

此外,如果用户在指定的延迟时间到期之前将鼠标移出链接,我想取消它的触发器。

有人可以帮我解决这个问题吗?

非常感谢你。

我终于成功实现了我的目标。

这是最终结果:

<!DOCTYPE HTML>
<html>
  <head>
    <title>Tooltip Testings</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <style type="text/css"> 
      body { margin: 60px auto; } p { padding:0; margin: 4px auto; text-align: center; }
    </style>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.min.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
    <script type="text/javascript">
    $(function() {
      $(document).tooltip({
        items: '.tooltip',
        show: 100,
        hide: 500,
        position: { my: 'center bottom', at: 'center top' },
        content: function( callback ) {
          var ARTid = this.id.split('_')[1];
          var TTtmr = setTimeout( function() {
            $.ajax({
              type: 'post',
              url: '/tooltip.php',
              data: 'i='+ARTid,
              success: function( data ) { callback( data ); }
            }); 
          }, 800 );
          $('.tooltip').mouseleave( function() { clearTimeout( TTtmr ); } );
        }
      });
    });
    </script>
  </head>
  <body>

    <p><a class="tooltip" id="i_283" href="articles/programming-in-php.html">PHP Article</a></p>
    <p><a class="tooltip" id="i_567" href="articles/programming-in-c.html">C+ Article</a></p>
    <p><a class="tooltip" id="i_741" href="articles/programming-in-aspx.html">ASPX Article</a></p>
    <p><a class="tooltip" id="i_283" href="articles/programming-in-java.html">Java Article</a></p>

  </body>
</html>

你可以试试这个:

$(function() {
      $(document).tooltip({
        items: '.tooltip',
        hide: 500,
        position: { my: 'center bottom', at: 'center top' },
        content: 'Testing jquery tooltips!',
        show: {
          effect: "slideDown",
          delay: 250
        }
      });
    });

show属性接受具有以下属性的object参数; effect, delay, duration, and easing

http://api.jqueryui.com/tooltip/#option-show

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM