how can i add fade to this code ?? im trying to make it look like something similar to this
http://jsfiddle.net/xmLk4/ i tried the code in it but i dont know how to add it correctly .
<html>
<head>
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/000080_Navy_Blue_Square.svg/2000px-000080_Navy_Blue_Square.svg.png"
// set image object src property to an image's src, preloading that image in the process
slideimages[1] = new Image()
slideimages[1].src = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/25/Red.svg/120px-Red.svg.png"
slideimages[2] = new Image()
slideimages[2].src = "http://static.tumblr.com/674bc8c8a561428e14d7c5abe10d696f/ijaflyo/IdQmnirks/tumblr_static_greenbox.png"
</script>
</head>
<body>
<img src="firstcar.gif" id="slide" width="948" height="403" />
<script type="text/javascript">
//variable that will increment through the images
var step=0
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.getElementById('slide').src = slideimages[step].src
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit()
</script>
</body>
</html>`
I'm not sure what are you actually asking.
Do you mean CSS transitions? If so, consider adding
transition:all 0.6s;
You can add it in your img style= "transition:all 0.6s;"
Try this now
function slideit(){
if (!document.images)
return
document.getElementById('slide').style.opacity = "0";
setTimeout(function(){
document.getElementById('slide').src = slideimages[step].src;
document.getElementById('slide').style.opacity = "1";
},500)
if (step<2)
step++
else
step=0
setTimeout(slideit,2500)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.