473,507 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript modification of IE's CSS expression

How, using javascript, can you set or change a CSS value
from something to something else which has the IE
proprietary format: expression(javasriptCode)?
I'd like to know the answer in general, but the specific
issue motivating this is that I have an image in a TD
which I am able to nicely align left/right/center/top
bottom/middle and set (stretch) to various sizes.

I'd like to be able to set the image size as a percent
of the enclosing TD (and other more complicated
scenarios). In IE, setting imgElem.style.height
makes the image get stuck to the top (though sized
correctly).

So I have the idea that I could make imgElem.height be
an expression for IE and calculate the actual height
that I want the image to be. Now, I agree that I
could store the necessary multiplicative factor in
a window.heightFactor variable, or better yet, have a
dummy function that the expression points to (as in
the example below), but is that really the best way
to go???
Any ideas?
Thanks,
Csaba Gabor from Vienna

PS, for those who haven't seen it, here's a simple
example of this expression business (only works with IE):
<body style="margin:0">
<script type='text/javascript'>
function process(value) {
if (value.charAt(value.length-1)!="%")
return value;
var img=document.getElementById('img');
return(img.offsetParent.offsetHeight *
value.substring(0,value.length-1) / 100);
}
</script>
<form action=''>
<table border style="height:100%">
<tr><td style="height:5%">Enter ratio:
<input type=text name=foo></td></tr>

<tr><td valign=bottom align=center><img id=img
style="height:expression(process(document.forms[0][0].value))"
src='pic.jpg'></td></tr>
</form>
</body>

Note that if you leave out the 'process' in that expression, then as
you put in the '%' of 50% that the image will be sized at 50%, but
blasted to the top of the TD.
Jul 23 '05 #1
3 4535
The following script doesn't answer my question of
how to set an expression(javascriptExpression) onto
a style element, but I think it is a little more
instructive than my previous example. Note that the
expression has nothing to couple it to the variable
window.fooVal. Indeed, even the 'process' function
is missing it and yet the updating is still immediate
(type in: 50%). This would seem to indicate a huge
amount of computational overhead. I'm supposing
that if any events trigger, expressions reevaluate.

Csaba

<body style="margin:0">
<script type='text/javascript'>
var fooVal="200";
function process() {
var value = window['foo'+'Val'];
if (value.charAt(value.length-1)!="%") return value;
var img=document.getElementById('img');
return(img.offsetParent.offsetHeight *
value.substring(0,value.length-1) / 100);
}
</script>
<form action=''>
<table border style="height:100%">

<tr><td style="height:5%">Enter ratio:
<input type=text
name=foo onPropertyChange="window.fooVal=this.value"></td></tr>

<tr><td valign=bottom align=center><img id=img
style="height:expression(process())" src='pic.jpg'></td></tr>

</table>
</form>
</body>
Jul 23 '05 #2
OK, I finally have it - setExpression allows
you to set an expression on a style property
on the fly with javascript (see also
removeExpression and document.recalc):
<body style="margin:0" onLoad="init()">
<script type='text/javascript'>
var tbVal="200";
function elem(id) {
return document.getElementById(id);}
function process() {
var value = window.tbVal;
if (value.charAt(value.length-1)!="%") return value;
var img=document.getElementById('img');
return(img.offsetParent.offsetHeight *
value.substring(0,value.length-1) / 100);
}

function init() {
var iStyl = elem('img').style;
iStyl.setExpression("height","process()");
elem('tbIn').focus();
}
</script>
<form action=''>
<table border style="height:100%">

<tr><td style="height:5%">Enter ratio:
<input type=text tabIndex=1 id=tbIn name=tbIn
onPropertyChange="window.tbVal=this.value"></td></tr>

<tr><td valign=bottom align=center><img id=img
src='pic.jpg'></td></tr>

</table>
</form>
</body>
Csaba Gabor from Vienna
Jul 23 '05 #3
*** Csaba Gabor wrote/escribió (Mon, 14 Mar 2005 23:25:29 GMT):
id=img
style="height:expression(process(document.forms[0][0].value


I'd try something like:

document.getElementById('img').style.height=docume nt.forms[0][0].value+'%';

If it works, you can get rid of the proprietary IE extension. If you're to
publish a web site that only works in Windows IE, you'd better write a real
app in VisualBasic or C++ ;-)
--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1231
by: MrPutty | last post by:
Hello, I've aquired some Javascript that will kick in when a IE version < 6 comes to visit. It positions elements with a position:fixed effect. I need to add control for one more div container....
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.