Her er _fade og __fading funktionerne:
- /**
- * Fades the object to a given fade value (0.0 - 1.0)
- *
- * @param {Integer} setOpacity The opacity that the element will have in the end of the fade-animation.
- * @param {String | Number} setSpeed The duration of the fading
- * @param {Function} callBack An optional callback function, that will be called when the fading has finished
- * @return An instance of the calling element
- * @type HTMLElement
- */
- this._fade = function(setOpacity, setSpeed, callBack)
- {
- if(this.timer)
- clearInterval(this.timer);
- var stringSpeeds = {
- "fast": 500,
- "normal": 1000,
- "slow": 2000};
- speed = (speed = stringSpeeds[setSpeed]) ? speed : setSpeed;
-
-
- if(!speed || isNaN(parseFloat(speed)))
- {
- speed = 1000;
- Frozen.debug("Remember to set fading speed!", 1);
- }
-
- var sensitivity = 10;
- var steps = speed/sensitivity;
- var msIEPattern = new RegExp("[0-9]+","g");
- var opacity = (opacity = this.getComputedStyle("opacity")) ? opacity : 1.0;
- var mozOpacity = (mozOpacity = this.getComputedStyle("-moz-opacity")) ? mozOpacity : 1.0;
- var msIEOpacity = (msIEOpacity = this.getComputedStyle("filter")) ? msIEOpacity : 100;
- if(msIEOpacity != 100)
- msIEOpacity = msIEPattern.exec(msIEOpacity);
-
- var diff = (parseFloat(setOpacity) - opacity) / steps;
-
- this.setStyle("opacity", opacity);
- this.setStyle("-moz-opacity", mozOpacity);
- this.setStyle("filter", "alpha(opacity="+msIEOpacity+")");
- /*
- Just a simple non-IE - IE division. IE doesnt support extra parameters in setInterval..
- */
- if(document.addEventListener)
- this.timer = window.setInterval(this._fading, sensitivity, diff, setOpacity, this, callBack);
- else
- {
- Frozen.debug(diff+ " - " +setOpacity+ " - "+ this+ " - " +callBack);
- this.timer = window.setInterval(this._fading(diff, setOpacity, this, callBack), sensitivity);
- }
- return this;
- }
-
- /**
- * The actually fade function, do not call this function
- *
- * @param {Integer} diff The difference to add or subtract to the opacity value for each step
- * @param {Integer} reuslt The final opacity value
- * @param {HTMLElement} self Because of the setInterval, this function will be called as a global function, therefor we have to set an argument of itself
- * @param {Function} callBack An optional callback function, that will be called when the fading has finished
- * @return An instance of the calling element
- * @type HTMLElement
- */
- this.__fading = function(diff, result, self, callBack)
- {
- var msIEPattern = new RegExp("[0-9]+","g");
- var opacity = parseFloat(self.getComputedStyle("opacity"));
- var mozOpacity = parseFloat(self.getComputedStyle("-moz-opacity"));
- var msIEOpacity = msIEPattern.exec(self.getComputedStyle("filter"));
- if(diff > 0)
- {
- if(!self.data)
- self.data = {};
- self.data["fadingUp"] = true;
- if(opacity >= result)
- {
- clearInterval(self.timer);
- if(callBack)
- callBack.call(self);
-
- return this;
- }
- }
- else
- {
- if(!self.data)
- self.data = {};
- self.data["fadingUp"] = false;
- if(opacity <= result)
- {
- clearInterval(self.timer);
- if(callBack)
- callBack.call(self);
- return this;
- }
- }
- opacity += diff;
- mozOpacity += diff;
- msIEOpacity += diff*100;
- self.setStyle("opacity", opacity);
- self.setStyle("-moz-opacity", mozOpacity);
- self.setStyle("filter", "alpha(opacity="+msIEOpacity+")");
-
- return this;
- }
Og her er hvordan de bliver kaldt i et simpelt eksempel:
- Frozen.ready(function()
- {
- //var frozenDom = new FrozenDOM();
- var div = $("#testDiv");
- div.onclick = function()
- {
- time = new Date();
- startTime = time.getTime();
- if(this.data["fadingUp"] || typeof(this.data["fadingUp"]) == "undefined")
- {
- this.fade(0.0, "fast", function()
- {
- Frozen.debug("Fading down: " + ((new Date()).getTime() - startTime));
- this.toggleClass("test");
- });
- }
- else
- {
- this.fade(1.0, "fast", function()
- {
- Frozen.debug("Fading up: " + ((new Date()).getTime() - startTime));
- });
- }
- }
- });
Det hele virker PERFEKT i FF, men IE virker selvfølgelig ikke..
Får denne fejl:
Detaljer om fejl på websiden
Meddelelse: Ugyldigt argument.
Linje: 539
Tegn: 4
Og linje 539 er der hvor setInterval bliver sat i IE versionen... Hvad er der galt?