Archives

October 18, 2007

Passing parameters to a function called with setTimeout

Filed under: Web development, javascript — bryan @ 10:44 pm

When creating my news ticker plugin, I came across a slight complication when using setTimeout() to calling a function which needed parameters passed to it.

Not having had much call to use setTimeout in the past, I simply put:

setTimeout(myFunction(parameter),myTimeout);

but that doesn’t work. An apparent solution (until tried in Internet Explorer) is:

setTimeout(myFunction,myTimeout,parameter);

It wasn’t as easy as I expected to find out how to get around this, but it turns out that all is needed is a “closure”:

setTimeout(function(){myFunction(parameter)},myTimeout);

October 17, 2007

BBC style news ticker

Filed under: Web development, javascript — bryan @ 11:56 pm

Wanting to create a news ticker along the lines of that used on the BBC news site, I took a look around for a handy plugin to do it, but with no success. So… I created my own, as a jQuery plugin.

A quick sample of how to use it follows, or you can see the news ticker in action. Continue reading BBC style news ticker