JavaScript
  Home arrow JavaScript arrow Page 5 - Understanding The JavaScript Event Mod...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Understanding The JavaScript Event Model (part 2)
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 29
    2002-07-10

    Table of Contents:
  • Understanding The JavaScript Event Model (part 2)
  • Back To Basics
  • How's The Weather Up There?
  • X Marks The Spot
  • Enter The Stalker
  • Of Keys And Clicks
  • A Few Modifications
  • Tonight's Menu
  • Reducing The Crime Rate
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Understanding The JavaScript Event Model (part 2) - Enter The Stalker
    (Page 5 of 10 )

    Here's another example, this one demonstrating how the current coordinates of the mouse pointer can be exploited to create a simple mouse trail. Take a look at the following example, which has a text string closely following the mouse pointer as it travels across the screen.

    <html>
    <head>
    <script language="JavaScript"> 
    function mouseTracker()
    {
    document.all.rock_n_roll.style.visibility="visible";
    document.all.rock_n_roll.style.left = event.x + 20;
    document.all.rock_n_roll.style.top = event.y + 20;
    }
    document.onmousemove=mouseTracker;
    </script>
    </head>
    <body>
    <div id="rock_n_roll" style="font-family:Arial; font-size: xx-small;
    position:absolute; visibility:hidden; background:black; color:
    white;">Why are you following me?</div>
    </body>
    </html>
    In this case, every time the mouse is moved, an event is generated and the mouseTracker() function is invoked. This function receives the current X and Y coordinates of the mouse pointer; it then uses these coordinates to move the layer containing the text string to a location 20 pixels behind the pointer.

    Here's the Netscape version of the example above - as you can see, it does exactly the same thing, except that it uses the "pageX" and "pageY" properties instead of the "x" and "y" properties.
    <html>
    <head>
    <script language="JavaScript"> 
    function mouseTracker(e)
    {
    document.rockroll.visibility="show"
    document.rockroll.pageX = e.pageX + 20
    document.rockroll.pageY = e.pageY + 20
    }
    document.captureEvents(Event.MOUSEMOVE);
    document.onMouseMove=mouseTracker;
    </script>
    </head>
    <body>
    <div id="rockroll" style="position:absolute; visibility:hidden;
    background:black; color:white;"><font face="Arial" size="-2">Why are you
    following me?</font></div>
    </body>
    </html>

    More JavaScript Articles
    More By Team Melonfire, (c) Melonfire


     

       

    JAVASCRIPT ARTICLES

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway