search
HomeWeb Front-endHTML TutorialEasyUI系列学习(六)-Tooltip(提示框)_html/css_WEB-ITnose

一、创建组件

0.Tooltip不依赖其他组件

1.使用class加载

<a href="#" class="easyui-tooltip" title="这是一个提示信息">Hover me</a>

2.使用js加载

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip();    })</script>

二、属性

1.position:消息框位置(left,right,top,默认bottom)

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip();    })</script>

2.content:消息框内容,可以是html

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            content: "<strong>我是html</strong>"        });    })</script>

3.trackMouse:为true时,允许提示框跟鼠标移动

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            trackMouse: true        });    })</script>

4.deltaX,deltaY:提示框具体左上角的位置

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            deltaX: 50,            deltaY:50        });    })</script>

5.showDelay,hideDelay延时多少毫秒显示/隐藏提示框,默认是200

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            showDelay: 1000,            hideDelay: 2000        });    })</script>

6.showEvent,hideEvent:激活显示/隐藏事件时候的提示框,默认为mouseenter,mouseleave

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            //鼠标单击是显示提示框            showEvent: "click",            //鼠标双击是隐藏提示框            hideEvent: "dblclick"        });    })</script>

三、事件

1.onShow,onHide:在显示/隐藏提示框的时候触发

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            onShow: function (e) {                alert("显示提示框的触发");            },            onHide: function (e) {                alert("隐藏提示框的触发");            }        });    })</script>

2.onUpdate:在提示框内容更新时触发,默认content为null

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            content: "这是新内容",            onUpdate: function (content) {                alert("内容被更新:" + content);            }        });    })</script>

3.onPosition:在提示框位置被改变的时候触发

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            onPosition: function (left, top) {                console.log("left:" + left + ",top:" + top);            }        });    })</script>

4.onDestroy:在提示框被撤销的时候触发

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            onDestroy: function (none) {                alert("提示框被销毁");            }        });        $("#tBox").click(function () {            $(this).tooltip("destroy");        });    })</script>

四、方法

1.options:返回属性对象

2.show,hide:显示/隐藏提示框

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({        });        $("#tBox").tooltip("show");        $("#tBox").tooltip("hide");    })</script>

3.update:更新content的内容

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({        });        //鼠标移动到”Hover me“时触发        $("#tBox").tooltip("update", "更新的内容");    })</script>

4.tip:返回tip元素对象;arraw返回箭头元素对象(实际就是提示框生成的两个div)

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            onShow: function () {                //div.tooltip.tooltip-bottom                console.log($("#tBox").tooltip("tip"));                //div.tooltip.tooltip-outer,div.tooltip-arrow                console.log($("#tBox").tooltip("arrow"));            }        });    })</script>

5.reposition:重置提示框位置

<a href="#" id="tBox" title="这是一个提示信息">Hover me</a><script>    $(function () {        $("#tBox").tooltip({            onShow: function () {                $(".tooltip-bottom").css("left", 500);            },            onHide: function () {                $("#tBox").tooltip("reposition");            }        });    })</script>

五、组件默认值

$.fn.tooltip.defaults.position = "right";

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools