/    Sign up×
Community /Pin to ProfileBookmark

Looking for a script that will rotate imgs onClick…

I’ve tried searching the forums and the scipt librory – both in vain. I’m guessing that I simply don’t know what terms to use in my search. In any case, here is what I want to happen: a user clicks on <img src=”1.jpg”> and it is replaced by 2.jpg. He clicks on 2.jpg and it is replaced by 3.jpg. So on until there are no more new images, in which case the loop goes back to one and starts over again.

If anyone can point me to a sctip I can use, I would be most thankfull!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JAug 13.2004 — Take a look here to see if one of these would be ok for you, there are different effects

www.huntingground.freeserve.co.uk/style/sldshow_1_5.htm

and

www.huntingground.freeserve.co.uk/style/sldshow_6_10.htm
Copy linkTweet thisAlerts:
@TheBearMayAug 13.2004 — Off the top of my head you could try something like:

[code=php]

var imgArr=["imgName.jpg", "another.jpg"...];
var imgNum = 0;

function rotateImg(){
imgNum++;
var nOfm = imgNum +1;
nOfm= nOfm + " of " + imgArr.length;
if(imgNum>imgArr.length-1) imgNum=0;
document.getElementById("imgItem").src=imgArr[imgNum]
return nOfM;
}
...
<img id="imgItem" onclick="documen.getElementById('imgText').nodeValue=rotateImg();"...
<span id="imgText"> </span>...
[/code]


Haven't tested this, but it should be close.
×

Success!

Help @Eugi 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 6.12,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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