/    Sign up×
Community /Pin to ProfileBookmark

Java Script image transtition

Hello, I have this JS, that is supposed to display one image, and every 2 seconds change too another image.
The images are uploaded to my webserver however this JS doesn’t seem to be working at all…Any help would be great..Its just supposed to show <Conference1.jpg> the every two second change to <Conference2.jpg>

[CODE]
<script type=”text/javascript”> image1=”http://www.mysite.org/images/conference1.jpg”; image2=”http://www.mysite.org/images/conference2.jpg”; function swap() { source = (test.getAttribute(“src”) != image1) ? image1 : image2; test.setAttribute(“src”, source); setTimeout(“swap()”, 2000); } window.onload = function() { test = document.getElementById(“test”); swap(); }</script> <img id=”test” /></div>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisAug 05.2008 — This might work a bit better:
&lt;script type="text/javascript"&gt;
image1="http://www.mysite.org/images/conference1.jpg";
image2="http://www.mysite.org/images/conference2.jpg";
function swap() {
source = (test.getAttribute("src") != image1) ? image1 : image2;
test.setAttribute("src", source);
setTimeout("swap()", 2000);
}

window.onload = function() {
test = document.getElementById("test");
swap();
}
&lt;/script&gt;
&lt;img id="test" src="http://www.mysite.org/images/conference1.jpg"&gt;
Copy linkTweet thisAlerts:
@budsterAug 05.2008 — Hi ChompGater

This article may help, it uses setInterval rather than setTimeout, to change the image. It also merges between them ( I don't know if you want that effect or not)

http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11530

Hope this helps
×

Success!

Help @ChompGator spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...