English 中文(简体)
MooTools - Tooltips
  • 时间:2024-09-17

MooTools - Tooltips


Previous Page Next Page  

MooTools provides different tooltips to design custom styles and effects. In this chapter, we will learn the various options and events of tooltips, as well as a few tools that will help you add or remove tooltips from elements.

Creating a New Tooltip

Creating a tooltip is very simple. First, we have to create the element where we will attach the tooltip. Let us take an example that creates an anchor tag and adds that to the Tips class in the constructor. Take a look at the following code.

<a id = "tooltipID" class = "tooltip_demo" title = "1st Tooltip Title" 
   rel = "here is the default  text  for toll tip demo" 
   href = "http://www.tutorialspoint.com">Tool tip _demo</a>

Take a look at the code used to create tooltip.

var customTips = $$( .tooltip_demo );
var toolTips = new Tips(customTips);

Example

The following example explains the basic idea of Tooltips. Take a look at the following code.

<!DOCTYPE html>
<html>

   <head>
      <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
      <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>
      
      <script type = "text/javascript">
         window.addEvent( domready , function() {
            var customTips = $$( .tooltip_demo );
            var toolTips = new Tips(customTips);
         });
      </script>
   </head>
   
   <body>
      <a id = "tooltipID" class = "tooltip_demo" title = "1st Tooltip Title" 
         rel = "here is the default  text  for toll tip demo" 
         href = "http://www.tutorialspoint.com">Tool tip _demo</a>
   </body>
   
</html>

You will receive the following output −

Output