Home arrow JavaScript arrow Page 4 - Special Effects with DHTML Rollovers
JAVASCRIPT

Special Effects with DHTML Rollovers


It’s common knowledge that JavaScript image rollover scripts became very popular in the early days of the Internet. While some people feel rollover effects have become perhaps, cliché, there are many ways to build upon simple rollover effects using JavaScript and style sheets. For the purpose of this tutorial, we’ll focus on several effects and the basics of how to set up images for creating rollover special effects with DHTML.

Author Info:
By: Ian Felton
Rating: 3 stars3 stars3 stars3 stars3 stars / 22
September 28, 2004
TABLE OF CONTENTS:
  1. · Special Effects with DHTML Rollovers
  2. · Enter the JavaScript
  3. · The Main Effect and Implementation
  4. · Putting it all Together

print this article
SEARCH DEVARTICLES

Special Effects with DHTML Rollovers - Putting it all Together
(Page 4 of 4 )

Now that all of the pieces have been explained, look at the entire source code below to see how to put it all together:

<HTML>
<HEAD>
<TITLE>Shudder</TITLE>
<STYLE TYPE="text/css">
<!—
#Central {position:absolute; left:0;  top:0; width:575; height:300; z-index:2; visibility:hidden;}
#Behind  {position:absolute; left:0;   top:0; width:575; height:300; z-index:1; visibility:hidden;} 
//-->
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
<!--

function browser_Sniff() {
  //Determines which browser and version is being used
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) &&
((agent.indexOf('spoofer')==-1) &&
(agent.indexOf('compatible') == -1)));
  this.ns2 = (this.ns && (this.major == 3));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4b = (this.ns && (this.minor < 4.04));
  this.ns4 = (this.ns && (this.major >= 4));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major == 2));
  this.ie4 = (this.ie && (this.major >= 4));
  this.op3 = (agent.indexOf("opera") != -1);
  this.win = (agent.indexOf("win")!=-1);
  this.mac = (agent.indexOf("mac")!=-1);
  this.unix = (agent.indexOf("x11")!=-1);
}

// VARIABLES

var is = new browser_Sniff();   // Calls Browser sniffing function

function standardize() {
// Once browser has been sniffed
// these conditionals set Netscape and Microsoft syntax
// to the same variable, so that only one function need be written
 if(is.ns4) {
   doc = "document";
   sty = "";
   htm = ".document"; }
 else if(is.ie4) {
   doc = "document.all";
   sty = ".style";
   htm = ""; }
}

// Sets variables for image manipulation
var bool = 1;
function Load_Name() {  //Creates layer objects
 Centralobj = eval(doc + '["Central"]' + sty);
 Behindobj = eval(doc + '["Behind"]' + sty);
}

function Position() {
 Centralobj.left = (available_width / 2) - 211;
 Centralobj.top = (available_height / 2) - 143;
 Centralobj.visibility = 'visible';
 Behindobj.left = (available_width / 2) - 211;
 Behindobj.top = (available_height / 2) - 143;
 Behindobj.visibility = 'visible';
}

function Shudder() {
 var x = Math.random();
 var y = Math.random();
 Behindobj.top = (available_height / 2) - (145 * y) - (Math.cos(x *10) + (x * y));
 Behindobj.left = (available_width / 2) - (100 * x) - (Math.sin(y *10) + (2 * y * x));
}
// -->
</script>
</HEAD>

<BODY BGCOLOR="BLACK" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLL="NO" onLoad="
if(is.ns4) {
     available_width=innerWidth;
     available_height=innerHeight;
   }
           else if(is.ie4) {
     available_width=document.body.clientWidth;
     available_height=document.body.clientHeight;
  };
standardize(); Load_Name(); setTimeout('Position()',.01);">
<DIV ID="Central"><IMG SRC="graphics/sundunes.jpg" width="422" height="286" onmousemove="Shudder()"></DIV>
<DIV ID="Behind"><IMG SRC="graphics/sundunes_b.jpg"></DIV>

</BODY>
</HTML>

The Shudder effect is just one example of how to use DHTML for special effects on your web page. Now that you have some basics, hopefully you will discover places where you can use DHTML effects to add some spice. To end with a cliché older than JavaScript rollovers, "the possibilities are endless."


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials