Groups | Blog | Home
all groups > dotnet jscript > march 2005 >

dotnet jscript : How to: Control "CSS" styles via JScript?


charliewest
3/11/2005 10:41:03 AM
I need to set the background-position of a style in real-time, with onload
event via JScript. Assuming this is possible, can anyone tell me how?

Steve Fulton
3/12/2005 6:58:17 AM
[quoted text, click to view]

RTFM.
background-position Attribute | backgroundPosition Property
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/backgroundposition.asp

--
Steve

We must believe in luck. For how else can we explain the success of
charliewest
3/12/2005 9:37:08 AM
Um... I'm familiar w/ this sample, and read-up a little before posting this
question. I might be way off, but this has nothing to do w/ my question.

The sample doesn't "set" STYLE properites, it simply applies already
hard-coded styles to objects dynamically. Again, I need to calculate the
actual position upon page load and literally set this style property in
real-time.

"En cuanto mas personas conozca, mas me gusta mi pero."
Camilo Jose Cela.


[quoted text, click to view]
charliewest
3/12/2005 9:51:04 AM
oh.. yes... i forgot to write RTFQ. Thanks,

[quoted text, click to view]
Serge Baltic
3/12/2005 11:10:54 AM
c> I need to set the background-position of a style in real-time, with
c> onload event via JScript. Assuming this is possible, can anyone tell
c> me how?

See the document.styleSheets property for details.

Something like CSS/workshop/author/dhtml/reference/collections/stylesheets.htm
in MSDN.

--
Serge

Steve Fulton
3/13/2005 7:37:18 AM
[quoting noramlized; sigs trimmed]

[quoted text, click to view]

Where in the FQ did you say that you had read up before posting? That
you knew anything about the backgroundPosition property (as opposed
to the (background-position attribute)?

How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html

The second example shows how to change the background position using
the backgroundPosition property. I will concede that the example uses
a hard-coded value; but you never gave any information about how to
calculate the actual position. I apologize for assuming that you knew
how to determine what background position you needed.

<body onload="
var elem = document.getElementById('someIdYouNegelectedToMention');
if (someConditionYouNegelectedToMention) {
var pos = someCalculationYouNegelectedToMention;
}
else {
pos = anAlternateCalculationYouNegelectedToMention;
}
elem.style.backgroundPosition = pos;
">

--
Steve

An army of sheep led by a lion could easily defeat an army of lions
AddThis Social Bookmark Button