/    Sign up×
Community /Pin to ProfileBookmark

setInterval fine in IE, choppy as hell in FF

I’m having a mountain of trouble with an image cycling script. It works fine in IE and FF/Moz if you’re only cycling a single image, but as soon as you introduce another image to the equation, FF/Moz becomes choppy and horrible. Anyone have any ideas as to where I’m going wrong?

[code=html]
<html>
<head>
<script language=”javascript” type=”text/javascript”>
<!–
imagecycle.Vars = [];
imagecycle.preload = 0;
function imagecycle(id, pix, linx, delay, imgname)
{
this.howMany = pix.length;
this.id = id;
this.pix = pix;
this.preloadPix(this.pix);
this.linx = linx;
this.imgname = imgname;
this.delay = delay * 500;
this.picCurrentNum = 0;
this.picCurrent = new Image();
this.picCurrent.src = this.pix[this.picCurrentNum];
imagecycle.Vars[id] = this;
}
imagecycle.prototype.preloadPix = function(pix)
{
if (imagecycle.preload == 1) {
temp_img = new Image();
for (a=0; a<pix.length; a++) {
temp_img.src = pix[a];
}
}
}
imagecycle.startPix = function()
{
var reg = imagecycle.Vars;
for (a=0; a<reg.length; a++) {
obj = imagecycle.Vars[a];
interval = setInterval(“imagecycle.slideShow(“+obj.id+”)”, obj.delay);
}
}
imagecycle.slideShow = function(id)
{
var reg = imagecycle.Vars;
var obj = imagecycle.Vars[id];
obj.picCurrentNum++;
if (obj.picCurrentNum == obj.howMany) {
obj.picCurrentNum = 0;
}
obj.picCurrent.src = obj.pix[obj.picCurrentNum];
document[obj.imgname].src = obj.picCurrent.src;
}
imagecycle.link = function(id)
{
var reg = imagecycle.Vars;
var obj = imagecycle.Vars[id];
document.location = obj.linx[obj.picCurrentNum];
}
images1 = new Array(2);
images1[0] = “test1.jpg”;
images1[1] = “test2.jpg”;
links1 = new Array(2);
links1[0] = “#”;
links1[1] = “#”;
new imagecycle(0, images1, links1, 5, “test1”);

images2 = new Array(3);
images2[0] = “test3.jpg”;
images2[1] = “test4.jpg”;
images2[2] = “test5.jpg”;
links2 = new Array(2);
links2[0] = “#”;
links2[1] = “#”;
links2[2] = “#”;
new imagecycle(1, images2, links2, 3, “test2″);

// End –>
</script>
</head>
<body onload=”imagecycle.startPix()”>
<img width=”200″ height=”150″ name=”test1″ src=”test1.jpg” /><br />
<img width=”200″ height=”150″ name=”test2″ src=”test3.jpg” />
</body>
</html>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 05.2005 — try using setTimeout() instead of setInterval(). They are not exactly the same thing...
Copy linkTweet thisAlerts:
@bartonfinkleauthorMay 06.2005 — I apologise if this sounds rude and I do appreciate you taking the time to reply, but I'm not sure you quite understand the function of the script. setInterval is used so that the image continues to cycle. setTimeout would mean the image changes once. The problem only exists in the Mozilla based browsers. I tried modifying it using setInterval set to a delay of 1 to call a function with a setTimeout set to the delay that I want the images to have before they change, but it didn't solve the problem at all. The problem is that the images stutter, change at the incorrect times, don't change at all, or flicker very quickly when you have two or more running at once. Having only one works fine in all browsers I have been able to test it in (IE5, 5.2 mac, 5.5, 6, FF1.02, Moz1.6, Camino & Safari) except for Opera.

actually... does anyone have any idea how to get the darned thing to work in Opera?
[code=html]
http://blah.blah.blah
Event thread: load
Error:
name: TypeError
message: Statement on line 42: Could not convert undefined or null to object
Backtrace:
Line 42 of linked script http://blah.blah.blah/imageCycle.js
interval = setInterval("imagecycle.slideShow(" + obj.id + ")", obj.delay);
Line 1 of script
imagecycle.startPix();
At unknown location
[statement source code not available]
[/code]
×

Success!

Help @bartonfinkle 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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