/    Sign up×
Community /Pin to ProfileBookmark

Really simple animation script – not working :(

This script works in Opera 9, IE 6 and IE 7, but not in Firefox ?

JS:

[code]
function d2h(d) {return d.toString(16);} // Thanks Felgall! [got it from from javascript.about.com]
var anim = {
startVal: 223,
endVal: 244,
curVal: 223,
aObj: null,
tOut: null,
start: function(obj) {
if (anim.tOut) clearTimeout(anim.tOut);
if (obj) {
anim.aObj = obj;
anim.curVal = anim.startVal;
}
anim.curVal++;
anim.aObj.style.backgroundColor = “#” + d2h(anim.curVal) + d2h(anim.curVal) + d2h(anim.curVal); // line 15
if (anim.curVal < anim.endVal) {
anim.tOut = setTimeout(anim.start, 20);
}
},
end: function() {
if (anim.tOut) clearTimeout(anim.tOut);
anim.aObj.style.backgroundColor = “#” + d2h(anim.startVal) + d2h(anim.startVal) + d2h(anim.startVal);
}
}
[/code]

HTML:

[code]
<a href=”#” onMouseOver=”anim.start(this)” onMouseOut=”anim.end()”>Page 1</a>
<a href=”#” onMouseOver=”anim.start(this)” onMouseOut=”anim.end()”>Page 2</a>
<a href=”#” onMouseOver=”anim.start(this)” onMouseOut=”anim.end()”>Page 3</a>
<a href=”#” onMouseOver=”anim.start(this)” onMouseOut=”anim.end()”>Page 4</a>
[/code]

This is what FireBug is showing me:

[code]
anim.aObj.style has no properties
start(-20)common.js (line 15)
anim.aObj.style.backgroundColor = “#” + d2h(anim.curVal) + d2h(anim.curVal) + …
[/code]

The error occurs on the second function call.
Please help ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiauthorApr 09.2007 — Nevermind, I fixed it, it seems that in Firefox, setTimeout adds some parameters (in this case the first parameter was -22 ?). So I changed
if (obj) {
to
if (typeof(obj)=="object") {
?
×

Success!

Help @Znupi 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 7.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

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: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,
)...