Hi all. I'm learning JS from pretty much scratch and the first thing I'm trying to do is simply make an image fade function. I just can't seem to make it work though, the image starts off at the right opacity (im this case 0.5) but after that the page goes white and the script never stops. It does seem to be counting up normally "opacity: 0.6 opacity: 0.7" etc. though.
Code:
<img src="1.jpg" id="pic1">
<script type="text/javascript">
var amount = 0.5;
var target = document.getElementById('pic1');
function fade() {
if (target.style.opacity < 1.0) {
target.style.opacity = amount;
amount = amount + 0.1;
document.write("<br>opacity: " + target.style.opacity);
setTimeout("fade()", 1000)
//fade();
}
}
fade();
</script>
edit I rewrote it to make it simpler but still having basically the same problem D:!