zoukankan      html  css  js  c++  java
  • jQueryToolstooltip

    老规矩,先上html和css,还是用官方的,只是去掉了些东西。

    HTML


    View Code
    <!DOCTYPE html>
    <html>
    <head>
      <title>jQuery Tools standalone demo</title>
    
        <!-- include the Tools -->
      <script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
    
      <link rel="stylesheet" type="text/css"
          href="./tooltip-generic.css"/>
    <style>
      #myform {
      border:1px outset #ccc;
      background:#fff  repeat-x;
      padding:20px;
      margin:20px auto;
      350px;
      font-size:12px;
      -moz-border-radius:4px;
      }
    
      #myform h3 {
      text-align:center;
      margin:0 0 10px 0;
      }
    
      /* http://www.quirksmode.org/css/forms.html */
      #inputs label, #inputs input, #inputs textarea, #inputs select {
      display: block;
       150px;
      float: left;
      margin-bottom: 20px;
      }
    
      #inputs label {
      text-align: right;
       75px;
      padding-right: 20px;
      }
    
      #inputs br {
      clear: left;
      }
    </style>
    </head>
    <body><form id="myform" action="#">
    
      <h3>Registration Form</h3>
    
      <div id="inputs">
    
        <!-- username -->
        <label for="username">Username</label>
        <input id="username" title="Must be at least 8 characters."/>
        <br />
    
        <!-- password -->
        <label for="password">Password</label>
        <input id="password" type="password" title="Make it hard to guess." />
        <br />
    
        <!-- email -->
        <label for="email">Email</label>
        <input id="email" title="We won't send you any marketing material." />
        <br />
    
        <!-- message -->
        <label for="body">Message</label>
        <textarea id="body" title="What's on your mind?"></textarea>
        <br />
    
        <!-- message -->
        <label for="where">Select one</label>
        <select id="where" title="Select one of these options">
          <option>-- first option --</option>
          <option>-- second option --</option>
          <option>-- third option --</option>
        </select>
        <br />
      </div>
    
      <!-- email -->
      <label>
        I accept the terms and conditions
        <input type="checkbox" id="check" title="Required to proceed" />
      </label>
    
      <p>
        <button type="button" title="This button won't do anything">
          Proceed
        </button>
      </p>
    
    </form>
    
    <!-- javascript coding -->
    <script>
      // execute your scripts when the DOM is ready. this is a good habit
      $(function() {
    
            // select all desired input fields and attach tooltips to them
          $("#myform :input").tooltip({
    
          // place tooltip on the right edge
          position: "center right",
    
          // a little tweaking of the position
          offset: [-2, 10],
    
          // use the built-in fadeIn/fadeOut effect
          effect: "fade",
    
          // custom opacity setting
          opacity: 0.7
    
          });
        });
    </script>
    </body>
    </html>

    CSS


    View Code
    /* simple css-based tooltip */
    .tooltip {
        background-color:#000;
        border:1px solid #fff;
        padding:10px 15px;
        width:200px;
        display:none;
        color:#fff;
        text-align:left;
        font-size:12px;
    
        /* outline radius for mozilla/firefox only */
        -moz-box-shadow:0 0 10px #000;
        -webkit-box-shadow:0 0 10px #000;
    }

    CSS可以不需要,这样显示的样子恶心了点。

    关键代码:

    View Code
    // select all desired input fields and attach tooltips to them
    $("#myform :input").tooltip({
    
    // place tooltip on the right edge
    position: "center right",
    
    // a little tweaking of the position
    offset: [-2, 10],
    
    // use the built-in fadeIn/fadeOut effect
    effect: "fade",
    
    tipClass:'tooltip', //  省却值:tooltip,少了这一行效果也是一样
    // custom opacity setting
    opacity: 0.7
    
    });

    使用

    这里是可能存在的最简单的工具提示的初始化:

      $("#myform :input").tooltip();

    配置

    属性默认值 描述
    cancelDefault true 自从1.1.0版。 当工具提示内容抓取 从 标题 触发器元素的属性 这个属性取消默认工具提示执行的行为 浏览器。 这是通过简单的移除 这个 标题 属性从触发器。

    你仍然可以检索/修改标题值通过调用 jQuery的 数据('title') 方法为触发。

    effect 'toggle' 指定了如何显示和隐藏的提示。 有两个 内置的效果,可以用作值:

    toggle 。 一个简单的显示/隐藏效果。 这是 默认

    fade 。 一个简单的淡入/淡出效果

    还有一个 幻灯片效果 不 包括在该工具本身。 你可以 构建 你自己的

    delay 30 指定工具提示依然可见多久后鼠标 叶子触发器。 这是必需的,如果tootip已 互动的内容和用户将需要时间去 tootip区域。 通过设置0工具提示也会消失 鼠标离开就从触发器元素。
    events Object 一个配置对象,它指定当工具提示会 显示和隐藏。 您可以指定不同的事件不同 类型的元素。 这里有默认值为这个 属性:
            events: {
    def: "mouseover,mouseout",
    input: "focus,blur",
    widget: "focus mouseover,blur mouseout",
    tooltip: "mouseover,mouseout"
    }

    JavaScript

    你可以阅读更多关于这方面的内容 这个 事件管理 一章。

    layout '<div/>' 自从1.2.0 HTML布局为生成的 工具提示。 可以很复杂的HTML布局如你所愿。 你 可以,例如,添加一个嵌套的 跨度 元素作为 箭的占位符。
    offset [0, 0] 精细地调节工具提示指定位置 这个 位置 属性。 看到 这个 定位细节 更多的 信息。
    opacity 1 透明的工具提示。 例如,0意味着不可见, 1意味着没有透明度(完全可见)和0.4意味着40% 工具提示显示的。 如果你的工具提示使用CSS背景 图像,你可以设置透明度的形象,如果它已经 保存在PNG24图形格式。 记住,互联网 IE 6不支持原生透明的PNG。
    position 'top center' 指定位置的工具提示。 看到 这个 定位细节 更多的 信息。 旧的格式:['top', 'center'] 是废弃,在未来将会被移除。
    predelay 0 自从1.1.0版。 指定了延迟(在 毫秒)工具提示显示之前。 默认情况下有 没有延迟。
    relative false 自从1.1.1。 默认情况下,工具提示位置 现在决定相对于文档(通过使用 这个 relative)的方法。 通过启用这个 产权工具提示的位置是相对确定的 父元素
    tip   一个jQuery选择器为一个单一的工具提示的元素。 对于 示例 # mytip 。 该选项仅有效如果你 要手动定义一个工具提示多个触发器 同时元素。 因为1.2.5 标题 属性仍然可以被用作工具提示内容。
    tipClass 'tooltip' 自从1.2.0。 CSS类名生成的 工具提示的元素。  
     

    事件

    确保你已经阅读 大约 事件 jQuery工具 。 所有事件监听器接收 这个 事件 对象 作为第一个参数。

    事件 触发事件
    onbeforeshow 在工具提示显示。 第二个参数是工具提示 要使用位置。 这是一个对象的值{top: integer, left: integer} 
    onShow 在工具提示显示。
    onBeforeHide 在工具提示是隐藏的
    onHide 当这个工具提示是隐藏的。

    下面的示例是一个onShow 回调函数, 淡出触发器元素当工具提示显示:

      $("label").tooltip({
     
    // change trigger opacity slowly to 0.8
    onShow: function() {
    this.getTrigger().fadeTo("slow", 0.8);
    } 
    });

    事件管理

    jQuery工具提示可以让你完全控制 工具提示 将显示或隐藏。 您可以指定不同的事件 不同类型的元素。 你可以控制这种行为 这个 事件 配置变量,它具有以下 默认值:

      events: {
    def: "mouseenter,mouseleave", // default show/hide events for an element
    input: "focus,blur", // for all input elements
    widget: "focus mouseenter,blur mouseleave", // select, checkbox, radio, button
    tooltip: "mouseenter,mouseleave" // the tooltip element
    }

    脚本 api

    首先确保你已经了解你自己 与 jQuery工具 脚本

    以下列出的是所有API方法:

    方法 返回值 描述/例子
    show() api 显示工具提示。
    hide() api 隐藏工具提示。
    isShown(fully) 布尔 返回 真正的 如果这个工具提示是可见的。 自从1.2.0 你也可以使用一个布尔型参数,保证了 函数返回 真正的 只有当这个工具提示是充分的 可见(在它的最终位置和不透明性)。
    getTip() jQuery 返回tooltip作为一个jQuery对象。
    getTrigger() jQuery 返回元素作为一个jQuery对象的触发。
    getConf() 对象 返回工具提示配置。

    内置的效果: fade

    内置的效果“渐”有它自己的一组配置选项 如下:

    属性 默认值 描述
    fadeInSpeed 400 淡入时速度显示工具提示,以毫秒为单位。
    fadeoutspeed 200 当工具提示的淡出速度是隐藏着的,以毫秒为单位。 
     
      下面有个自定义事件的例子:http://jquerytools.org/demos/tooltip/custom-effect.htm

      

      tab:传送门

      tab(幻灯片):传送门

      tooltip:传送门

      overlay:传送门

      dateinput:传送门

  • 相关阅读:
    第二十四篇 玩转数据结构——队列(Queue)
    第二十三篇 玩转数据结构——栈(Stack)
    第二十二篇 玩转数据结构——构建动态数组
    第二十一篇 Linux中的环境变量简单介绍
    第二十篇 Linux条件测试语句相关知识点介绍
    第十九篇 vim编辑器的使用技巧
    第十八篇 Linux环境下常用软件安装和使用指南
    第十六篇 nginx主配置文件参数解释
    RAID磁盘阵列是什么(一看就懂)
    如何删除顽固文件或文件夹?
  • 原文地址:https://www.cnblogs.com/qionghua/p/2580190.html
Copyright © 2011-2022 走看看