473,770 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opacity

Hi,

I'm trying to get and set an element's opacity, but I'm stuck with,
what a hell of surprise, Internet Explorer. As for getting the
element's opacity, I have the following (not working) lines of code:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
opacity =
targetObject.fi lters.item("DXI mageTransform.M icrosoft.Alpha" ).Opacity;

Setting it, I tried:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
targetObject.se tAttribute( "style", "filter: alpha(opacity=" +
opacity + ")" );

None work. I have digged these out from some MSDN article, but they
aren't working, at least they don't work in to me available IE 6.0. Do
you have better (i.e. working) ways of yours?

Thanks

Darko
Nov 19 '07 #1
16 2969
Darko wrote:
I'm trying to get and set an element's opacity, but I'm stuck with,
what a hell of surprise, Internet Explorer. As for getting the
element's opacity, I have the following (not working) lines of code:
I don't know what was wrong there, but I see you think that opacity is
only available for IE. There's an equivalent feature in Mozilla browsers
using custom CSS properties. You'll have to sniff for the browsers and
branch your code to handle it (totally) differently, but it's definitely
possible. Not that I've ever used it, but I have seen itt.
Nov 20 '07 #2
VK
On Nov 19, 10:38 pm, Darko <darko.maksimo. ..@gmail.comwro te:
As for getting the
element's opacity, I have the following (not working) lines of code:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
opacity =
targetObject.fi lters.item("DXI mageTransform.M icrosoft.Alpha" ).Opacity;

Setting it, I tried:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
targetObject.se tAttribute( "style", "filter: alpha(opacity=" +
opacity + ")" );

None work. I have digged these out from some MSDN article
Do you still remember which one?
but they
aren't working, at least they don't work in to me available IE 6.0.
Of course they don't: setAttribute method has nothing to do with it.
Do you have better (i.e. working) ways of yours?
Not mine, but tested working:

http://www.quirksmode.org/js/opacity.html
Nov 20 '07 #3
VK wrote:
Not mine, but tested working:
http://www.quirksmode.org/js/opacity.html
I knew I'd seen it somewhere :)
Nov 20 '07 #4
VK wrote:
On Nov 19, 10:38 pm, Darko <darko.maksimo. ..@gmail.comwro te:
>As for getting the
element's opacity, I have the following (not working) lines of code:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
opacity =
targetObject.f ilters.item("DX ImageTransform. Microsoft.Alpha ").Opacity;

Setting it, I tried:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
targetObject.se tAttribute( "style", "filter: alpha(opacity=" +
opacity + ")" );

None work. I have digged these out from some MSDN article

Do you still remember which one?
Probably
http://msdn2.microsoft.com/en-us/lib...ipting_Filters or
a previous version.
>but they
aren't working, at least they don't work in to me available IE 6.0.

Of course they don't: setAttribute method has nothing to do with it.
To be precise, setAttribute() does not seem to work there *for IE*.
>Do you have better (i.e. working) ways of yours?

Not mine, but tested working:

http://www.quirksmode.org/js/opacity.html
However, it does not make sense in passing ranges from 0 to 10 and then
computing the required value twice. With the division for `opacity', there
is even a rounding error involved, needlessly. It makes more sense have
`value' range from 0 to 1 (thereby to pass the percentage x% as 0.0x to the
function); the computation will have to be done only once (for `filter'),
and the used values will be as exact as the layout engine allows it:

function setOpacity(valu e)
{
testObj.style.o pacity = value;
testObj.style.f ilter = 'alpha(opacity= ' + value * 100 + ')';
}
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Nov 20 '07 #5
On Nov 19, 11:38 am, Darko <darko.maksimo. ..@gmail.comwro te:
Hi,

I'm trying to get and set an element's opacity, but I'm stuck with,
what a hell of surprise, Internet Explorer. As for getting the
element's opacity, I have the following (not working) lines of code:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
opacity =
targetObject.fi lters.item("DXI mageTransform.M icrosoft.Alpha" ).Opacity;

Setting it, I tried:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
targetObject.se tAttribute( "style", "filter: alpha(opacity=" +
opacity + ")" );

None work. I have digged these out from some MSDN article, but they
aren't working, at least they don't work in to me available IE 6.0. Do
you have better (i.e. working) ways of yours?
Does the element have a layout? In IE terms, it's gotta have position
or height/width for proprietary hasLayout to be be true.

DXImageTransfor m can work for background images, too, but doesn't let
you set any other background-properties (like background-position).

Regarding other comments on this thread: Opacity is CSS3, not a moz-
specific css. it works in Mozilla, Webkit and Opera.

Garrett
Thanks

Darko
Nov 20 '07 #6
On Nov 20, 4:03 pm, Stevo <ple...@spam-me.comwrote:
Darko wrote:
I'm trying to get and set an element's opacity, but I'm stuck with,
what a hell of surprise, Internet Explorer. As for getting the
element's opacity, I have the following (not working) lines of code:

I don't know what was wrong there, but I see you think that opacity is
only available for IE. There's an equivalent feature in Mozilla browsers
using custom CSS properties. You'll have to sniff for the browsers and
branch your code to handle it (totally) differently, but it's definitely
possible. Not that I've ever used it, but I have seen itt.
No, I don't think that. I use "opacity" regularly for other browsers,
but
it doesn't work with IE. So I googled out that IE needs this filter
thing,
which they claim works by accessing .filters subobject, but it seems
as if it
does not. So I gave up and did as it was only possible, using
..style.filter = ..., which I like less than the proposed solution from
MSDN
(which doesn't work). Never mind.
Nov 21 '07 #7
On Nov 19, 8:38 pm, Darko <darko.maksimo. ..@gmail.comwro te:
Hi,

I'm trying to get and set an element's opacity, but I'm stuck with,
what a hell of surprise, Internet Explorer. As for getting the
element's opacity, I have the following (not working) lines of code:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
opacity =
targetObject.fi lters.item("DXI mageTransform.M icrosoft.Alpha" ).Opacity;

Setting it, I tried:

if ( targetObject.fi lters && targetObject.fi lters.length 0 )
targetObject.se tAttribute( "style", "filter: alpha(opacity=" +
opacity + ")" );

None work. I have digged these out from some MSDN article, but they
aren't working, at least they don't work in to me available IE 6.0. Do
you have better (i.e. working) ways of yours?

Thanks

Darko
As for opacity, now that I gave in and had it .style.filter = "...",
it finally
works well with IE, too. Another problem though - Konqueror. It seems
to ignore:
opacity
-moz-opacity
-khtml-opacity
filter

Wtf. does it need? Does Konqueror actually support element's opacity?
I wouldn't mind
the bloody Konqueror not working properly with my site, but as I
understand Safari uses
the same KHTML engine, so I reckon if Konqueror doesn't work (as it
doesn't), then Safari
won't neither. Am I right? Or Safari uses a KHTML branch that actually
supports the standard?

Thanks
Nov 21 '07 #8
On Dec 4, 11:47 pm, David Mark <dmark.cins...@ gmail.comwrote:
On Dec 4, 8:22 pm, Peter Michaux <petermich...@g mail.comwrote:
On Dec 4, 12:17 am, dm...@cinsoft.n et wrote:
On Nov 21, 4:35 pm, Peter Michaux <petermich...@g mail.comwrote:
[snip]
// if (early release edition of Firefox && val === 1) {
// // This trick is from Scriptaculous
// // Some version of Firefox (before 1.5?) flickers
I've seen this recently. It drove me to distraction while I was
working on a special effects module. I don't think it was an early
release though. I am pretty sure it was the latest major release.
I've never managed to make it flicker on any version.

It only seems to happen when animating the opacity with a timer and
only when starting from 1. Start from .99999 or whatever and it goes
away. I eventually changed the timing of something and got it worked
out of my effects module without resorting to the .99999 hack.
// // when animatingopacit yup to a value of 1.
// // If this trick is to be used the test will probably be
// // expensive and should only be preformed the first time.
// //
// // Apparently using this trick increases the weight of
// // the DOM, for rendering speed?
I am not sure what that means, but as I recall, setting .999999
instead of 1 makes no visible difference, other than to eliminate the
annoying flicker.
Someone told me or I read that by setting several elements with
opacity makes the DOM "heavier". I can only assume they mean it takes
longer to render or that it takes more RAM or something like that. The
idea of limiting this 0.99999 trick to only the versions of FF that
need it was to avoid adding this "weight" to browsers that don't need
the trick. The importance given to this "weight" issue sounded a
little like flaky to me.

I think it does take a little more work to render a semi-transparent
element, but the idea of using .999999 in lieu of 1 is silly.
I believe the flicker issue included animating from an opacity below 1
up to 1 in which case the animation needed to stop before 1. I can't
say this is silly.

[snip]
For the most part it does. Doing it for table rows or groups of table
rows would seem an odd thing to do anyway. Add a disclaimer about
table rows at the top and you are done. Feel free to add it to your
repository.
I'm starting a branch for opacity. I think it will serve as a good
first DHTML example.

Peter
Dec 5 '07 #9
On Dec 7, 11:59 am, Peter Michaux <petermich...@g mail.comwrote:

Yes by using this wrapper it would allow someone to write an
implementation like this.

function myApply(obj, f) {
obj._temp = f;
// some number of arguments
obj._temp(args, arguments[1], arguments[2],
arguments[3], arguments[4]);
delete obj._temp;

}
Never mind the bugs :)

--
Peter
Code Worth Recommending Project
http://cljs.michaux.ca/trac
Dec 7 '07 #10

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

Similar topics

1
4784
by: Dean Edwards | last post by:
I am attempting to change the opacity of an image. I can modify opacity ok: function flip(pic, opacity){ pic.style.filter = 'alpha(opacity='+opacity+')'; } But I'm not familiar with javascript. How can I read the existing opacity value?
0
3913
by: kaeli | last post by:
All, The following is an example of what I'm trying to do: I have a box set to be partially transparent. I want the text in the box to NOT be partially transparent. This works in IE, but NN7 has the text still at 75% opacity. Can anyone tell me what I'm doing wrong? TIA. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
3
10231
by: Marek Mänd | last post by:
This posting will express my concern about the future of css3 forthcoming recommendation. I think for long time now, that the current implementation of CSS attribute opacity is less than usable in practical real life situations. The soon forthcoming CSS3 recommendation does not serve the public interests in this area not at all. The problem relies in the definition what opacity is, how it is to applied to page elements. In past 5...
6
3721
by: Robert A. Boudra | last post by:
As you will probably guess, I'm just starting out with VB.net although I'm a long time VB developer. I was playing around with the Opacity property of a form and have found that I can set the property at design time or in code just fine, but as soon as I move the form to a new location on the screen, it becomes completely opaque. If I then try to set the opacity property again, I get an error message. Any idea what's going wrong? Bob
1
2637
by: mhoeneveld | last post by:
I am writing a small script to fade the opacity of an image/object. The script itself works fine only I do have some unwanted behaviour. I do use a tablecell object and the mouseover/mouseout to activate the script. In the same cell are some links listed and when you move the cursor over the links the image starts to flicker. This is because of the getElementById that identifies each link as an object. Anyone knows how I can solve...
2
2347
by: reidarT | last post by:
I want a windows form to act like the one in Outlook when you get a new message and it is visible for about a couple of seconds and then the opacity decreases and the form dissapears in the end I have tried with Dim p As Integer Dim Vent As Integer For p = 100 To 0 Step -1 Me.Opacity = p For Vent = 1 To 100000
15
3728
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it throws error. How I can change the opacity of an element in Firefox.
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.