[thelist] [JavaScript] way around these global vars?
Tom Dell'Aringa
pixelmech at yahoo.com
Tue Feb 7 13:28:53 CST 2006
--- Christian Heilmann <codepo8 at gmail.com> wrote:
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
> var img=o.style.backgroundImage.toString();
>
o.style.backgroundImage=(!/_on/.test(img))?img.replace('.gif','_on.gif'):img.replace('_on.gif','.gif');
>
> with o being the button object ?
> <snip>
> > clearing the interval is also a good idea and timeout is evil :)
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Ok - I have it working now, digged the test on '_on' to use the ternary to serve up the right
image - that's right up my alley. I can't really use interval using onload though - this happens
when a user clicks a button. I understand how setInterval() works, but I don't really see how to
make it work here using onclick. I suppose I could set it onclick and clear it immediately?
Was able to get around the button object undefined issue by just testing the args length.
I know "they" say timeout is evil, but in practice I've never experienced it. Right now this works
nicely, below -- comments?
-----------------------------
buttonFeedback = {
currentBtn:null,
showHit:function(btn)
{
if(arguments.length < 1)
{ var img = this.currentBtn.style.backgroundImage.toString();
this.currentBtn.style.backgroundImage = (!/_on/.test(img)) ? img.replace('.gif','_on.gif') :
img.replace('_on.gif','.gif');
return;
}
else
{
this.currentBtn = btn;
var img = this.currentBtn.style.backgroundImage.toString();
this.currentBtn.style.backgroundImage = (!/_on/.test(img)) ? img.replace('.gif','_on.gif') :
img.replace('_on.gif','.gif');
setTimeout("buttonFeedback.showHit()", 500)
}
}
}
http://www.pixelmech.com/
http://www.crossandthrone.com/
Professor Rumford: 'But I still don't understand about hyperspace.'
The Doctor: 'Well, who does?'
K9: 'I do.'
Doctor: 'Shut up, K9!'
More information about the thelist
mailing list