Click to See Complete Forum and Search --> : dont let the ametuer frustrate you


domie_
07-27-2003, 02:19 AM
<HEAD>


<!-- start: WarpGear JavaScript Fader v1.0 -->

<BODY onLoad="fade()" bgcolor="#000000">
<div id="fader" style="position:absolute; top:35px; left:50px; width:600px; text-align:center;"></div>
<!-- adjust style= to position messages -->

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: WarpGear Software (jsfader@warpgear.com) -->
<!-- Web Site: http://www.warpgear.com/developer -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// texts:
// Your messages wich may contain regular html tags but
// must at least contain: [ <font color='{COLOR}'> ]
// Use single quotes [ ' ] in your html only. If you need
// a double quote in the message itself use an escape
// sign like this: [ \" ] (not including the brackets)

var texts = new Array(
"<font size='+3' color='{COLOR}' face='Trebuchet MS'><strong>B l a k d a i s i e z</strong></font>",
"<font size='+2' color='{COLOR}' face='Trebuchet MS'><strong>.sylera</strong></font>",
"<font size='+2' color='{COLOR}' face='Trebuchet MS'><strong>.com</strong></font>",
"<img src='http://www.geocities.com/domieoshea/temporary.gif'/>");

var bgcolor = "#000000"; // background color, must be valid browser hex color (not color names)
var fcolor = "#FFFFFF"; // foreground or font color
var steps = 20 // number of steps to fade
var show = 600; // milliseconds to display message
var sleep = 35; // milliseconds to pause inbetween messages
var loop = true; // true = continue to display messages, false = stop at last message

// Do Not Edit Below This Line
var colors = new Array(steps);
getFadeColors(bgcolor,fcolor,colors);
var color = 0;
var text = 0;
var step = 1;

// fade: magic fader function
function fade() {

// insert fader color into message
var text_out = texts[text].replace("{COLOR}", colors); // texts should be defined in user script, e.g.: var texts = new Array("<font color='{COLOR}' sized='+3' face='Arial'>howdy</font>");

// actually write message to document
if (document.all) fader.innerHTML = text_out; // document.all = IE only
if (document.layers) { document.fader.document.write(text_out); document.fader.document.close(); } // document.layers = Netscape only

// select next fader color
color += step;

// completely faded in?
if (color >= colors.length-1) {
step = -1; // traverse colors array backward to fade out

// stop at last message if loop=false
if (!loop && text >= texts.length-1) return; // loop should be defined in user script, e.g.: var loop=true;
}

// completely faded out?
if (color == 0) {
step = 1; // traverse colors array forward to fade in again

// select next message
text += 1;
if (text == texts.length) text = 0; // loop back to first message
}

// subtle timing logic...
setTimeout("fade()", (color == colors.length-2 && step == -1) ? show : ((color == 1 && step == 1) ? sleep : 50)); // sleep and show should be defined in user script, e.g.: var sleep=30; var show=500;
}
// getFadeColors: fills Colors (predefined Array)
// with color hex strings fading from ColorA to ColorB

// note: Colors.length equals the number of steps to fade
function getFadeColors(ColorA, ColorB, Colors) {
len = Colors.length;

// strip '#' signs if present
if (ColorA.charAt(0)=='#') ColorA = ColorA.substring(1);
if (ColorB.charAt(0)=='#') ColorB = ColorB.substring(1);

// substract rgb compents from hex string
var r = HexToInt(ColorA.substring(0,2));
var g = HexToInt(ColorA.substring(2,4));
var b = HexToInt(ColorA.substring(4,6));
var r2 = HexToInt(ColorB.substring(0,2));
var g2 = HexToInt(ColorB.substring(2,4));
var b2 = HexToInt(ColorB.substring(4,6));

// calculate size of step for each color component
var rStep = Math.round((r2 - r) / len);
var gStep = Math.round((g2 - g) / len);
var bStep = Math.round((b2 - b) / len);

// fill Colors array with fader colors
for (i = 0; i < len-1; i++) {
Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
r += rStep;
g += gStep;
b += bStep;
}
Colors[len-1] = ColorB; // make sure we finish exactly at ColorB
}

// IntToHex: converts integers between 0-255 into a two digit hex string.
function IntToHex(n) {
var result = n.toString(16);
if (result.length==1) result = "0"+result;
return result;
}

// HexToInt: converts two digit hex strings into integer.
function HexToInt(hex) {
return parseInt(hex, 16);
}

// body tag must include: onload="fade()" bgcolor="#000000" where bgcolor equals bgcolor in javascript above
// End -->
</script>


<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

</body>

________________________________

[COLOR=red]i have modified this simple fading text script, but it wont work on my site. nothing appears! do i have to adjust the 'style=postition' ?? or insert the html into a particular place? ahh help

Exuro
07-27-2003, 09:09 PM
It works great in IE6 and Opera7, but not in Mozilla Firebird 0.6... However, it works fine in all 3 if you change line 47 from this:

if (document.all) fader.innerHTML = text_out; // document.all = IE only

to this:

if (document.getElementById) document.getElementById('fader').innerHTML = text_out;
else if (document.all) fader.innerHTML = text_out; // document.all = IE only

domie_
07-28-2003, 04:34 AM
still the same problem.
i am thinking now it has something to do with pagebuilder (*sigh*) - a very limited online editor provided by geocities. i have to start off using this until i have hosting arranged.
are you sure adjusting the position
( <div id="fader" style="position:absolute; top:35px; left:50px; width:600px; text-align:center;"></div> )
will make no difference ?

thanks anyway

domie_
07-28-2003, 04:37 AM
ah, i just tried putting the code on a new page, alone- without any other text or images.. and it worked.
what does that i mean i have to change?

Exuro
07-28-2003, 01:43 PM
I'm not sure what that means... I'm sure there's hundreds of things that could cause that to happen. If you uploaded it someplace and gave us a link to the page we might be able to help though...