Friday, November 24, 2006

Controling Opacity

I have found this very helpful in doing "flash-like" java scripts driven by user input. Takes 1 minute to create transition effect lib with this function.


P.S.: Oh!
The only thing left for you to implement isIE()!!!!!

function setObjectOpacity(obj, opacity)
if (isIE()) = "alpha(opacity:"+opacity+")";
opacity = (opacity == 100)?99.999:opacity;//99.9 for Firefox flicker bug

// Konqueror, Safari = opacity / 100;
// Old Mozilla and Firefox = opacity / 100;
// CSS3, Safari , new Firefox (Gecko) = opacity / 100;

Java Script multi-threading

We all know that it is not possible,...but... using timers along with path-through routines that don't block might sound like a cool alternative. I have tried it and it works - picture this:

function doLongTask(x,y,z, callback)
this.X = x;
this.Y = y;
this.Z = z;

doLongTask.prototype.threadSpin = _longtask_threadspin;

function _longtask_threadspin()
//instead of long loops save your intermediate state in this.{vars}

if (this.X%100==0) this.Z = this.Y - 100; //some logic that would have been in a tight loop

if (this.X>1000) this.doneCallback();


And now we can easily:

var task = new doLongTask(1,2,3,doneLongTask);
var tmr = setInterval(task.threadSpin, 10/*time slice!!!*/);

function doneLongTask()
task.Z // result of task
clearInterval(tmr);// kill 'thread'