setting an image to have a transparent background? (.getElement().setAttribute("style", ".....)

262 views
Skip to first unread message

darkflame

unread,
Oct 12, 2008, 7:30:43 PM10/12/08
to Google Web Toolkit
I'm trying to make a standard image have a code-dependant uniform
transparency background, and for it to work across all browsers.
Doing this in css is easy, and works, but GWT seems to not be having
it.

I'm using simply;

temp.getElement().setAttribute("style", "filter: alpha(opacity=65);
opacity: 0.65");

Where temp is just an image.

This doesn't seem to have any effect, but I'm not sure why.
The same style code in CSS works, does it have to be different when
applied this way? And what referance do I look at to see the changes
made?




Paul Robinson

unread,
Oct 12, 2008, 8:10:21 PM10/12/08
to Google-We...@googlegroups.com
What happens if you try:

Style style = temp.getElement().getStyle();
style.setProperty("filter", "alpha(opacity=65)");
style.setProperty("opacity", "0.65");

firebug will tell you what style is in force for each element

HTH
Paul

darkflame

unread,
Oct 12, 2008, 8:28:43 PM10/12/08
to Google Web Toolkit
That method worked, I wasnt aware of that method of doing it.
Cheers! :)

My own method, incidently, always worked in Firefox, and firebug
simply showed "opacity: 0.65;" for the style, without the
"alpha(opacity=65);" for IE present at all.

Jason Morris

unread,
Oct 13, 2008, 3:34:49 AM10/13/08
to Google-We...@googlegroups.com
As a rule of thumb, never setAttribute, when there is a property for that
element that does the same job. For example, use setClassName() instead of
setAttribute("class", ...), and getStyle().setProperty() instead of
setAttribute("style").

IE has problems handing setAttribute with any "special" values. So even when it
comes to setting the URL for an image, rather use the setSrc() method in
ImageElement.

I wish someone had told me this earlier when I started coding JavaScript :P

Thomas Wrobel

unread,
Oct 13, 2008, 6:58:53 AM10/13/08
to Google-We...@googlegroups.com
Cheers for the advice, I'll use those methods in future. :)

2008/10/13 Jason Morris <lem...@gmail.com>:

--
~~~~~~
Reviews of anything, by anyone;
www.rateoholic.co.uk
Please try out my new site and give feedback :)

Ponthiaux Eric

unread,
Oct 13, 2008, 7:42:58 AM10/13/08
to Google-We...@googlegroups.com
Could you use png images instead ?

Playing with specials browser attributes is a tricky thing . Basically
it will multiply your work at least by 4 ( IE , Firefox , Safari , Opera ).

regards.

Thomas Wrobel a écrit :

Thomas Wrobel

unread,
Oct 13, 2008, 7:53:56 AM10/13/08
to Google-We...@googlegroups.com
No, because the goal is to make something fade in an out :)

I already got it working on IE/Firefox and Opera now, havnt tested Safari yet.
Opera/Firefox both seem to work very smoothly with it, in fact. IE
works but a little slower to update.

I do use PNG images a lot though..lovely format. Not to hard to fix it
to work with IE6 either.
I only wish I could work out how to set the fallback colour for when
the transparancy dosnt work.

2008/10/13 Ponthiaux Eric <ponthia...@gmail.com>:

Lothar Kimmeringer

unread,
Oct 13, 2008, 7:54:17 AM10/13/08
to Google-We...@googlegroups.com
Ponthiaux Eric schrieb:

> Could you use png images instead ?

AFAIR IE has problems with transparency when showing PNGs (my copy
of GWT in Action is at home, so I can't look it up at the moment).


Regards, Lothar

darkflame

unread,
Oct 13, 2008, 8:25:56 AM10/13/08
to Google Web Toolkit
Indeed.
But you can use a fix to get around it;
http://www.twinhelix.com/css/iepngfix/demo/
Reply all
Reply to author
Forward
0 new messages