IMG
FaderThis page demonstrates a simple, cross browser image fader. For unsupported browsers, the images are simply switched.
This work is licensed under a Creative Commons License.
var imgFader = new ImgFader(ida, idb, time); ... imgFader.start();
ida
id
of the first imageidb
id
of the second imagetime
Include the file img-fader.js
in your document:
<script type="text/javascript" src="img-fader.js"> </script>
Todo:
div#img-fader { position: relative; } div#img-fader img { display: block; position: absolute; top: 0; left: 0; }
Todo:
onload = function() { var imgFader = new ImgFader("img-a", "img-b", time); }
onclick
fadingtime = 2.5; <div id="img-fader" onclick="imgFader.start()"> <img id="img-a" src="img1.png" /> <img id="img-b" src="img2.png" /> </div>
onmouseover
fadingtime = 2; <div id="img-fader" onmouseover="imgFader.start()"> <img id="img-a" src="img1.png" /> <img id="img-b" src="img2.png" /> </div>
onclick
fadingfade to image
time = 1; <div id="img-fader" onclick="imgFader.start()"> <p id="img-a">fade to image</p> <img id="img-b" src="img2.png" /> </div>
opacity
(Mozilla 1.7+, Safari 1.2+)