This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Stylesheets > March 2007 > Control font color





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Control font color
mistral

2007-03-25, 11:19 pm

Simple question: how better set font color in script?

<script type="text/javascript">
<!--

//Secify scroller contents
var line=new Array()
line[1]="Typewriter script"
line[2]="It brings up the text you want..."
line[3]="One letter at a time"
line[4]="You can add and subtract lines as you like."
line[5]="It's very cool and easy to use"

//Specify font size for scoller
var ts_fontsize="12px"

//--Don't edit below this line

var longestmessage=1
for (i=2;i<line.length;i++){
if (line[i].length>line[longestmessage].length)
longestmessage=i
}

//Auto set scroller width
var tscroller_width=line[longestmessage].length

lines=line.length-1 //--Number of lines

//if IE 4+ or NS6
if (document.all||document.getElementById){
document.write('<form name="bannerform">')
document.write('<input type="text" name="banner"
size="'+tscroller_width+'"')
document.write(' style="background-color: '+document.bgColor+';
color: '+document.body.text+'; font-family: verdana; font-size:
'+ts_fontsize+'; font-weight:normal; border: medium none"
onfocus="blur()">')
document.write('</form>')
}

temp=""
nextchar=-1;
nextline=1;
cursor="";
function animate(){
if (temp==line[nextline] & temp.length==line[nextline].length &
nextline!=lines){
nextline++;
nextchar=-1;
document.bannerform.banner.value=temp;
temp="";
setTimeout("nextstep()",1000)}
else if (nextline==lines & temp==line[nextline] &
temp.length==line[nextline].length){
nextline=1;
nextchar=-1;
document.bannerform.banner.value=temp;
temp="";
setTimeout("nextstep()",1000)}
else{
nextstep()}}

function nextstep(){

nextchar++;
temp+=line[nextline].charAt(nextchar);
document.bannerform.banner.value=temp+cursor
setTimeout("animate()",25)}

//if IE 4+ or NS6
if (document.all||document.getElementById)
window.onload=animate
// -->
</script>

regards,
mistral

Jukka K. Korpela

2007-03-25, 11:19 pm

Scripsit mistral:

> Simple question: how better set font color in script?


This group discusses style sheets, not scripts. There's a connection of
course, but this seems to be well on the scripting side; try
comp.lang.javascript if you can't find the answer in the JavaScript
tutorials and references that you normally use or in the FAQs.

> document.write(' style="background-color: '+document.bgColor+';
> color: '+document.body.text+'; font-family: verdana; font-size:
> '+ts_fontsize+'; font-weight:normal; border: medium none"
> onfocus="blur()">')


You seem to use the very old methods of changing a document via scripting;
the modern approach uses the W3C DOM and not document.write(). But if you
keep using the dated approach, generating HTML markup that contains a style
sheet embedded into an attribute, then you have a purely CSS question
indeed, though a very trivial one: how to set font color in _CSS_.

The answer is
color: black;
or
color: #000;
or
color: #000000;
to mention the most commonly used variants. Check CSS tutorials for more
details.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

mistral

2007-03-25, 11:19 pm

"Jukka K. Korpela" <jkorp...@cs.tut.fi> wrote:
> Scripsit mistral:
>
>
> This group discusses style sheets, not scripts. There's a connection of
> course, but this seems to be well on the scripting side; try
> comp.lang.javascript if you can't find the answer in the JavaScript
> tutorials and references that you normally use or in the FAQs.
>
>
> You seem to use the very old methods of changing a document via scripting;
> the modern approach uses the W3C DOM and not document.write(). But if you
> keep using the dated approach, generating HTML markup that contains a style
> sheet embedded into an attribute, then you have a purely CSS question
> indeed, though a very trivial one: how to set font color in _CSS_.
>
> The answer is
> color: black;
> or
> color: #000;
> or
> color: #000000;
> to mention the most commonly used variants. Check CSS tutorials for more
> details.
>
> --
> Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/

-----------

thank you.

mistral

Osmo Saarikumpu

2007-03-25, 11:19 pm

mistral wrote:

> Simple question: how better set font color in script?


Simple answer: replace following string:

color: '+document.body.text+';

with:

color:red;

Or create a variable, e.g. ScrollerTextColor and assign it a value:

var ScrollerTextColor = 'red';

and refer to it instead of document.body.text.

Even simpler answer: forget about that script. Them comments:

//if IE 4+ or NS6

are a hint of obsoleteness.

Osmo

mistral

2007-03-25, 11:19 pm

> mistral wrote:
[color=darkred]
> Simple answer: replace following string:


> color: '+document.body.text+';


> with:


> color:red;


> Or create a variable, e.g. ScrollerTextColor and assign it a value:


> var ScrollerTextColor = 'red';


> and refer to it instead of document.body.text.


> Even simpler answer: forget about that script. Them comments:


> //if IE 4+ or NS6


> are a hint of obsoleteness.


> Osmo

---------
OK, I forget about that script.. Here a new code that fully comply
all HTML/CSS standards.
What I want to correct - in fact, it consists of two scripts, that is
not convenient. I want join all in one script. I need also repeat
typewriter(set loop function). To remove background and border, it
seems, i just need remove border, padding, background attributes from
div.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Typewriter Example</title>
</head>

<body>

<h1>Typewriter Effect Example</h1>

<script type="text/javascript">

function Typewriter(sName)
{ // PROPERTIES
this.counter = 0;
this.name = sName;
this.text = "";
this.speed = 50; // in milliseconds

// METHODS
this.addText = AddText;
this.next = Next;
this.setSpeed = SetSpeed;
this.write = Write;

// FUNCTIONS
function AddText(s)
{ this.text = s
}
function Next()
{ document.getElementById('typewriter_output').innerHTML =
this.text.substr(0, this.counter++);
}
function SetSpeed(iSpeed)
{ this.speed = iSpeed;
}
function Write()
{ setInterval(this.name+".next()",this.speed);
}
}

</script>

<div id="typewriter_output" style="width:400px;border:1px black
solid;padding:1em;background:#f3f3f3;"></div>

<script type="text/javascript">
var myTypewriter = new Typewriter("myTypewriter");
myTypewriter.addText("Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Suspendisse eu nisi nec nunc tempor pharetra. Morbi
viverra. Proin scelerisque.");
myTypewriter.write();
</script>

</body>
</html>

mistral


Osmo Saarikumpu

2007-03-26, 7:19 pm

mistral wrote:

> OK, I forget about that script.. Here a new code that fully comply
> all HTML/CSS standards.


Please upload your code and provide an URL instead of sending code.

> What I want to correct - in fact, it consists of two scripts, that is
> not convenient. I want join all in one script. I need also repeat
> typewriter(set loop function).


Please note Mr. Korpela's advice concerning the correct group. You
should get the above mentioned aspects working before asking for
presentational help.

> To remove background and border, it
> seems, i just need remove border, padding, background attributes from
> div.


Yes. Remove, modify, apply presentation from elsewhere... these all are
more or less trivial matters to be attended after the script's
functionality.

Osmo
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews