Note: This post was imported from the very old Twod.co.uk post archives.
This snippet of code will produce a JavaScript function which you can then attach via a JavaScript call and shake the user’s Internet browser.
Place this anywhere before you’re going to call the function, or remove the surrounding <script> tags and place it within an external JavaScript file.
<script type=”text/javascript”>
function shake(n) {
if (parent.moveBy) {
for (i = 10; i > 0; i–) {
for (j = n; j > 0; j–) {
parent.moveBy(0,i);
parent.moveBy(i,0);
parent.moveBy(0,-i);
parent.moveBy(-i,0);
}
}
}
}
</script>
An example of this function being called using the onclick method would look as follows:
<input type=”button” onclick=”javascript:shake(200)” value=”Shake Me!” />
This will produce (go ahead, click for an example of the effect):
Share this with friends:
Like what you've just read? Share it to your friends using your favourite service below:
Comments:
Add a Comment: