Table of Contents
Learn more
Home Web Front-end JS Tutorial Mootools 1.2教程 Tooltips_Mootools

Mootools 1.2教程 Tooltips_Mootools

May 16, 2016 pm 06:46 PM

We'll also take a closer look at tooltip options and events, as well as some tools for adding and removing tooltips from elements. Finally, we will learn how to have multiple tooltips in different styles on one page.
The Basics
Creating a new tooltip
Creating a new tooltip is easy. First, let’s create a link to which we want to add a tooltip:
Reference code:

Copy the code The code is as follows:

MooTools 1.2 tooltips will display the values ​​of the title and rel attributes in links by default. If there is no rel attribute, the href attribute value will be displayed.
Now create a new default toolbar tip:
Reference code:
Copy code The code is as follows:

var customTips = $$('.tooltipA');
var toolTips = new Tips(customTips);

Since no styles are used, you will see to a tooltip like this:
Tool tip 1
Use styles for your tooltips
MooTools gives you a lot of control over its output - let’s take a look at the html code for the tooltip :
Reference code:
Copy code The code is as follows:

// You can Specify
in options >



Pay attention to the top and bottom divs. You can use them to easily add rounded corners or other styling effects to the top and bottom.
Now, let’s create our first option and add some CSS. The above html code will be rendered with a CSS style named "options.className". By giving our tooltip a CSS class name, we can give it an independent style without affecting other MooTools tooltips on the page.
Reference code:



Copy code The code is as follows: var customTipsB = $$( '.tooltipB');
var toolTipsB = new Tips(customTipsB, {
className: 'custom_tip'
});


Finally, we add some more CSS:
Reference code:



Copy code The code is as follows: .custom_tip .tip {
background-color: #333
padding: 5px
}
.custom_tip .tip-title {
color: #fff
background-color: #666
font-size: 20px
padding: 5px
}
.custom_tip .tip-text {
color: #fff
padding: 5px
}


Tool tip 2
Options
There are only five options in total in the Tips category, each of which is very self-explanatory (that is, you can understand what it means at a glance).
showDelay
The default value is 100
An integer in milliseconds that will determine how long the tooltip will wait after the mouse is moved over the element.
hideDelay
The default value is 100
Same as showDelay above, but this value (also in milliseconds) will determine how long it takes to hide the tooltip when the mouse leaves the element.
className
Defaults to null
As you can see in the example above, this allows you to set a CSS class name for the tooltip container.
offsets
The default is x:16, y:16
This will determine the distance of the tooltip from your element, the x value is the distance to the right of the element, and the y value is the distance from the element down ( If the fixed option is specified as false, the distance will be relative to the mouse pointer, otherwise it will be the distance relative to the element).
fixed
Defaults to false
This setting determines whether the tooltip follows the mouse when your mouse moves over the element. If set to true, the tooltip will not move with the movement of the mouse pointer, but will just stay at a fixed position near the element.
Events
Like everything else in this class, tooltip events are still very simple. It has two events: onShow and onHide, which will work as you expect.
onShow
This event will be triggered when the toolbar is displayed. If you set a delay, this event will fire until the tooltip is displayed.
onHide
is the same as the onShow event above, but it is triggered when the tool tip is hidden. If a delay is set, this event will also fire until the tooltip is hidden.
Methods
The Tips class has two methods - attach and detach. Through these two methods, you can add a tool tip to a specified element (of course, these tool tips will have the same settings), Or remove the tooltip from a specific element.
.attach();
To add a tooltip to a new element, you only need to add .attach(); after the Tip object, and finally put the selector of this element in parentheses .
Reference code:
Copy code The code is as follows:

toolTips.attach('# tooltipID3');

.dettach();
This method is the same as the .attach method, but their behavior is completely opposite. First, write the Tip object, then add .dettach(); after the element, and finally put the selector of this element in parentheses.
Reference code:
Copy code The code is as follows:

toolTips.dettach('# tooltipID3');

Code Example
In this example, we will create two different instances of the Tip plugin so that we can have two different styles of tooltips. We will also integrate the options, events and methods we saw above.
Reference code:
Copy code The code is as follows:

var customTips = $$('.tooltip');
var toolTips = new Tips(customTips, {
// This will set the delay time for tooltip display
showDelay: 1000 , // The default is 100
// This will set the delay event for tooltip hiding
hideDelay: 100, // The default is 100
// This will add a CSS style to the tooltip's container div
// This way you can have two different styles of toolbar tips on one page
//
className: 'anything', // The default is null
// This will set x and y Offset values ​​for
offsets: {
'x': 100, // Default is 16
'y': 16 // Default is 16
},
// This will set the tool Prompt whether to follow the mouse
// Set to true and the mouse will not be followed
fixed: false, // The default is false
// If you call this function outside the options
// and put This function stays here
// It flashes and has a smooth gradient effect
onShow: function(toolTipElement){
// Pass in the tooltip object
// You can make them Fade to fully opaque
// Or make them a little transparent
toolTipElement.fade(.8);
$('show').highlight('#FFF504');
},
onHide: function(toolTipElement){
toolTipElement.fade(0);
$('hide').highlight('#FFF504');
}
});
var toolTipsTwo = new Tips('.tooltip2', {
className: 'something_else', // The default is null
});
// You can use the .store(); method to change rel The value of
// thereby changing the value of the tool tip
// You can use the following code
$('tooltipID1').store('tip:text', 'You can replace the href with whatever text you want.');
$('tooltipID1').store('tip:title', 'Here is a new title.');
// The following code will not change the tool tip The text of
$('tooltipID1').set('rel', 'This will not change the tooltips text');
$('tooltipID1').set('title', 'This will not change the tooltips title');
toolTips.detach('#tooltipID2');
toolTips.detach('#tooltipID4');
toolTips.attach('#tooltipID4');

Tool tip 1

Tool tip is detached

Tool tip 3

Tool tip detached then attached again.

A differently styled tool tip

Learn more

Read through the Tips section in the MooTools documentation. In addition, here is a very good article written by David Walsh about Customizing Mootools Tips.

Download a zip package containing everything you need

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles