Website buttons with images that change on mouseover provide your visitors a more dynamic experience. They also send a subtle instruction to click the button. Choose your normal-state button and the one that is displayed when a user places the mouse pointer over the button. HTML and use JavaScript to achieve this meaningful addition to your Web page.
- Open a text or HTML editor and insert the following: var roArray=new Array () function setrollover(OverImg,docImgName) { if (! Document.images)return if (docImgName == null) docImgName = document.images[document.Images.Length-1].name roArray[docImgName]=new Object roArray[docImgName].overImage = new Image roArray[docImgName].over image.src=OverImg } function rollover(docImgName) { if (! Document.images)return if (! roArray[docImgName])return if (! roArray[docImgName].outImage) { roArray[docImgName].outImage = new Image roArray[docImgName].outImage.src = document.Images[docImgName].src } document.Images[docImgName].src=roArray[docImgName].over image.src } function rollout(docImgName) { if (! Document.images)return if (! roArray[docImgName])return document.Images[docImgName].src=roArray[docImgName].outImage.src } //>
- Locate the area for the button and set the following: HREF="mydoc.html" onMouseOver = "rollover('myimage')" onMouseOut = "rollout('myimage')" >
setrollover("overbutton.jpg", "myimage") //> Replace "mydoc.html" with your file name. Replace "mainbutton.jpg and overbutton.jpg" with the image name of your main and mouseover buttons, respectively. - Save your file. Sure the images are in the same directory as your HTML document, or on the way in your "SRC" and "setrollover" attributes. Test by double-clicking on the file on your system.
How to change an image on a mouse over in HTML Format
Website buttons with images that change on mouseover provide your visitors a more dynamic experience. They also send a subtle instruction to click the button. Choose your normal-state button and the one that is displayed when a user places the mouse pointer over the button. HTML and use JavaScript to achieve this meaningful addition to your Web page.
- Open a text or HTML editor and insert the following: var roArray=new Array () function setrollover(OverImg,docImgName) { if (! Document.images)return if (docImgName == null) docImgName = document.images[document.Images.Length-1].name roArray[docImgName]=new Object roArray[docImgName].overImage = new Image roArray[docImgName].over image.src=OverImg } function rollover(docImgName) { if (! Document.images)return if (! roArray[docImgName])return if (! roArray[docImgName].outImage) { roArray[docImgName].outImage = new Image roArray[docImgName].outImage.src = document.Images[docImgName].src } document.Images[docImgName].src=roArray[docImgName].over image.src } function rollout(docImgName) { if (! Document.images)return if (! roArray[docImgName])return document.Images[docImgName].src=roArray[docImgName].outImage.src } //>
- Locate the area for the button and set the following: HREF="mydoc.html" onMouseOver = "rollover('myimage')" onMouseOut = "rollout('myimage')" >
setrollover("overbutton.jpg", "myimage") //> Replace "mydoc.html" with your file name. Replace "mainbutton.jpg and overbutton.jpg" with the image name of your main and mouseover buttons, respectively. - Save your file. Sure the images are in the same directory as your HTML document, or on the way in your "SRC" and "setrollover" attributes. Test by double-clicking on the file on your system.
How to change an image on a mouse over in HTML Format
By Howtodotips
Website buttons with images that change on mouseover provide your visitors a more dynamic experience. They also send a subtle instruction to click the button. Choose your normal-state button and the one that is displayed when a user places the mouse pointer over the button. HTML and use JavaScript to achieve this meaningful addition to your Web page.