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.
Special Effects with DHTML Rollovers - Enter the JavaScript (Page 2 of 4 )
Next some JavaScript is needed before getting to the body of the HTML document. Since naming conventions are different in Internet Explorer and Netscape when working with JavaScript, a short function is called that determines the type of browser being used. The browser sniff function is used in tandem with another function called standardize which standardizes the way style sheet objects are called with Internet Explorer and Netscape Navigator. The HTML Guru (http://htmlguru.com) provided these functions and both remain useful after six years of using them.
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 = ""; }
For simplicity sake, assign variables to the style sheet objects that were defined in the beginning. Doing this will save a lot of typing. The Load_Name() function will accomplish that task.
One more function is required before getting to the actual Shudder function. The Position function places all of the images in the correct location and makes them visible. It finds the available height and width of the page and divides that by 2 to get the center point. If the images were placed on this point, the top-left corner of the images would be in the center point of the screen. Since the image should be centered, pixels are subtracted from the left and top positions to place the images center near the actual center of the screen. Once the images are placed, they are turned to a visible state.