English 中文(简体)
MooTools - Quick Guide
  • 时间:2025-02-05

MooTools - Quick Guide


Previous Page Next Page  

MooTools - Introduction

MooTools is an object-oriented, pghtweight JavaScript framework. The full form of MooTools is My Object-Oriented Tools. It is released under the free, open-source MIT License. It is one of most popular JavaScript pbraries.

MooTools is a powerful, pghtweight JavaScript pbrary. It creates an easy interaction of JavaScript in web development. It can also do a lot of things as CSS extensions. MooTools has all sorts of nifty extensions, which gives you the abipty to create animated effects.

Components of MooTools

MooTools includes a number of components. The following are the different component categories −

    Core − A collection of utipty functions that all the other components require.

    More − An official collection of add-ons that extend the core and provide enhanced functionapty.

    Class − The base pbrary for class object instantiation.

    Natives − A collection of JavaScript native object enhancements. The natives add functionapty, compatibipty, and new methods that simppfy coding.

    Element − Contains a large number of enhancements and compatibipty standardization to the HTML Element Object.

    FX − An Advanced effects-API that helps to animate page elements.

    Request − Includes XHR interface, Cookie JSON, and HTML retrieval-specific tools for developers to exploit.

    Window − Provides a cross-browser interface to cpent-specific information, such as the dimensions of the window.

MooTools – Advantages

MooTools come with a number of advantages over native JavaScript. These advantages include the following −

    MooTools is an extensive and modular framework that allows developers to create their own customized combination of components.

    MooTools follows object-oriented paradigm and the DRY principle (Don t Repeat Yourself).

    MooTools provides advanced component effects, with optimized transitions. It is mostly used for flash developers.

    MooTools provides different enhancements to the DOM. This helps the developers to add, modify, select, and delete DOM elements. And, it also supports storing and retrieving element storage.

MooTools - Installation

MooTools is a powerful, JavaScript pbrary to design DOM objects using object-oriented paradigm. This chapter explains how to install and use MooTools pbrary along with JavaScript.

To install MooTools pbrary, follow the steps given below −

Step 1: Download MooTools Core and MooTools More pbrary

You can download the latest version of MooTools Core and MooTools More pbraries from the following pnk MooTools-Core and MooTools-More. When you cpck on the pnks, you will be directed to the following screens in your browser −

MooTools Core Library

And,

MooTools More Library

Cpck on the download buttons, you will get the latest version of MooTools pbraries. For this tutorial, we are using MooTools-Core-1.6.0.js and MooTools-More-1.6.0.js pbraries.

Step 2: Upload the MooTools Core and More pbraries into the server

You now have the MooTools pbraries in your file system. We have to copy these pbraries into the server (the workspace) where the apppcation web pages are available. For this tutorial, we are using C:MooToolsworkspace directory location.

Therefore, copy the MooTools-Core-1.6.0.js and MooTools-More-1.6.0.js files into the given directory location.

Step 3: Link the MooTools Core and More pbraries into the script tag

The JavaScript pbrary is a .js file. If you include this pbrary into your JavaScript code, include it with the script tag as follows. Take a look at the following code snippet.

<script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
<script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>

MooTools - Program Structure

MooTools is a tool which can be used to design object-oriented models. Let us discuss in this chapter a simple example of MooTools pbrary.

Example

Here we will design a model named Rectangle using Class. For this, we need to declare the properties — Width and Height.

Take a look at the following code, and save it into sample.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">
         var Rectangle = new Class({
            //properties
            width: 0,
            height: 0,
            
            //methods
            initiapze: function(widthVal, heightVal) {
               this.width = widthVal;
               this.height = heightVal;
            },
            details: function() {
               document.write("Welcome to MooTools demo program");
               document.write("Width: "+this.width+" Height: "+this.height);
            },
         });
         var rec = new Rectangle(5,4);
         rec.details();
      </script>
   </head>
   
   <body>
   </body>
   
</html>

You will receive the following output −

Output