Book Image

MooTools 1.2 Beginner's Guide

Book Image

MooTools 1.2 Beginner's Guide

Overview of this book

MooTools is a simple-to-use JavaScript library, ideal for people with basic JavaScript skills who want to elevate their web applications to a superior level. If you're a newcomer to MooTools looking to build dynamic, rich, and user-interactive web site applications this beginner's guide with its easy-to-follow step-by-step instructions is all you need to rapidly get to grips with MooTools.
Table of Contents (14 chapters)
MooTools 1.2 Beginner's Guide
Credits
About the Authors
About the Reviewer
Preface

Time for action—the $time() function


We're going to see how fast (or slow) you click a button:

  1. First, we'll grab the start time and place it in an object called startTime. Right below it, we'll call the alert function to print out a message soliciting the user to click on the OK button. Right after that, we'll get the ending time and place it into an object called endTime.

    var startTime = $time();
    alert('Click on the OK button.');
    // The $time() function will be called again as soon as the user presses 'OK' to get the endTime.
    var endTime = $time();
    
  2. Next, we need to calculate the difference between endTime and startTime. Let's place that value inside an object called totalTime.

    var startTime = $time();
    alert('Click on the OK button.');
    // The $time() function will be called again as soon as the user //presses "OK" to get the endTime.
    var endTime = $time();
    var totalTime = endTime - startTime;
    
  3. Finally, we want to print out the results. We'll use the .write() JavaScript method to write the results...