User:Bawolff/sandbox/tick-fade2.js
< User:Bawolff | sandbox
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
//use fade transitions as oposed to slide. needs to load before Azatoth's script. Tested in Opera and firefox. May work in MSIE.
importScript('User:AzaToth/monobook.js'); //this will only import if not already
Ticker.prototype.tick = function( self ) {
if( self.current_index >= self.current_text.length ) {
window.clearInterval( self.intervalID );
window.setTimeout( self.tickAway, self.next_delay, self ); //goto out ransition instead of next
return;
}
if (self.current_index === 0) {
self.workspace.textContent = self.current_text;
}
setOpacity(self.workspace, (self.current_index/self.current_text.length));
self.current_index++;
}
Ticker.prototype.tickAway = function( self ) {
if( self.current_index <= 0 ) {
//After going out, hit next
window.clearInterval( self.intervalID );
self.next(self);
return;
}
if (self.current_index === self.current_text.length) {
//so it repeats itself after being hit the first time
self.intervalID = window.setInterval( self.tickAway, self.tick_delay, self );
}
setOpacity(self.workspace, (self.current_index/self.current_text.length));
self.current_index -= 3; //fade out 3x faster then fade in
}
var setOpacity = function(elm, opacity/*1 being full visible, 0 being invisible*/) {
if (!setOpacity.method) {
//standard way (CSS3)
if (elm.style && (typeof elm.style.opacity != "undefined")) {
setOpacity.method = "std";
}
else if (elm.style && (typeof elm.style.MozOpacity != "undefined")) { //old moz
setOpacity.method = "oldMoz";
}
else if (elm.style && (typeof elm.style.filter != "undefined")) {
setOpacity.method = "MSIE";
}
else {
setOpacity.method = "none";
throw new Error("opacity is not supported on this platform (or this script needs to be fixed to include support on your platform");
}
}
switch (setOpacity.method) {
case "std":
elm.style.opacity = opacity;
break;
case "oldMoz":
elm.style.MozOpacity = opacity;
break;
case "MSIE":
elm.style.filter = "alpha(opacity=" + opacity*100 + ")"; //No guarantees this works
break;
default:
return false; //not an exception, so you could catch the other exception, and still use func
break;
}
}