The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 21, 2019, 12:02:00 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Javascript window shaker  (Read 5282 times)
mampy
Journeyman
***
Offline Offline

Posts: 68


View Profile
« on: February 10, 2009, 09:07:16 AM »

I can think of a few fun ways to use this, Devilish  but this is a simple example of javascript and shows
how to attach an event to a particular trigger in the DOM. 

 Whenever the end user tries to type in the input box, the window goes nuts on them...

  Im a total javascript noob and thought id post this for anyone on their way behind me learning javascript its a simple
demonstration of an event/trigger situation thats simple enough for a 'tard like me to understand
and learn from  ROFLMAO

 The following simple example is a good way to see where javascript intervenes with html if
you were as clueless as me about where to even start:

Code:


<html> 

<head>
 <SCRIPT LANGUAGE="JavaScript">
 <!--

 var qDuration=1000;
 var qCounter=0;
 function quake()
  { // the horizontal displacement
  var deltaX=1; // make sure the browser support the moveBy method
  if (window.moveBy)
    { for (qCounter=0; qCounter<qDuration; qCounter++)
      {
        // shake left
        if ((qCounter%4)==0)
          {
              window.moveBy(deltaX, 0);
          }
         // shake right
        else if ((qCounter%4)==2)
          {
             window.moveBy(-deltaX, 0);
          }
        // speed up or slow down every X cycles
        if ((qCounter%30)==0)
          {
           // speed up halfway
           if (qCounter<qDuration/2)
             {
                deltaX++;
             }
           // slow down after halfway of the duration
           else
             {
               deltaX--;
             }
         }
      }
    }
  }
 
 -->
 </script> 
</head>     

<BODY onLoad="quake();">

       <input type="button" onclick="quake();" value="quake me baby!">
       <br>Type Some text in here and see what happens!
       <br>
       <input type="text" onkeypress="quake();"></input>
       <br>

</body> 

</html>


 ROFLMAO
« Last Edit: February 10, 2009, 09:15:32 AM by mampy » Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: February 10, 2009, 09:23:11 AM »

Quite interesting, if slightly novel.
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: February 10, 2009, 02:27:14 PM »

::seizes up, PinkHat calls 911::

ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!