|
-
Feb 12th, 2012, 06:41 AM
#2
Re: Change Img function Not working
Hi there billboy,
When you see "<!--", "if(document.images)" and the evil "eval" in a script, you may be pretty sure that it is outdated. 
Have a look at this slightly more modern version...
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<base href="http://node_charts_production.s3.amazonaws.com/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>swap image example</title>
<style type="text/css">
body {
background-color:#f0f0f0;
}
#demo {
display:block;
margin:30px auto 0;
box-shadow:#333 5px 5px 10px;
}
</style>
<script type="text/javascript">
/****** these values may be edited ******/
var speed=4000; /* image change rate */
var repeats=4; /* number of changes */
/****************************************/
var count=0;
var preloads=[];
function preload(){
for(var c=0;c<arguments.length;c++) {
preloads[preloads.length]=new Image();
preloads[preloads.length-1].src=arguments[c];
}
}
preload('85b6d5036c50481eb6f020372d4765ec.png','cc9dcdc0389a7ff2c8af40ff6007e51c.png');
function swapImage(){
obj=document.getElementById('demo');
obj.src=(obj.src==preloads[0].src)?preloads[1].src:preloads[0].src;
if(count++==repeats-1) {
alert("That's it.\n\nTime's up."); /* the alert can, of course, be removed */
return;
}
setTimeout(function(){swapImage();},speed);
}
window.addEventListener?
window.addEventListener('load',function(){setTimeout(function(){swapImage();},speed)},false):
window.attachEvent('onload',function(){setTimeout(function(){swapImage();},speed)});
</script>
</head>
<body>
<div>
<img id="demo" src="85b6d5036c50481eb6f020372d4765ec.png" alt="Mortgage Rate Chart">
</div>
</body>
</html>
~ the original bald headed old fart ~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|