473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Setting Opacity

Frinavale
9,735 Expert Mod 8TB
So, the opacity style is rather annoying because every browser seems to handle it differently. I guess it's because opacity wasn't included in the w3c standards to begin with...mind you if it had been included from the get-go, I have my doubts on whether this would have changed anything that we have to deal with today.

Anyways, enough ranting....I'm attempting to place a <div> over top of my content while an asynchronous call to the server is taking place. This is done to prevent the user from submitting any additional data to the server during "special" processes...

I'd like to set the opacity of this <div> to about 50% so that it looks all "pretty" and the user knows that they aren't able to access any of the content in the area behind the <div>.

Some strange stuff is happening in IE7 and 8.
The <div> is appearing over top of the content correctly....but the opacity settings are very strange. It starts at about 50% at the middle of the <div> but as it spreads outwards it fades to 0%. It's kind of neat (a half faded circle in the center that fades to nothing)...but it's not what I want.

What am I doing wrong here?

How do I change this so that the entire <div> is faded to 50% instead of just a circle in the middle of my <div>?


Expand|Select|Wrap|Line Numbers
  1. function Processing() {
  2.     //shield is the <div> that is used  to cover the content and already has the the position style set to absolute.
  3.     var shield = document.getElementById('ctl00_CPH_MainContent_myControl_shield');
  4.     shield.style.display = 'block';
  5.  
  6.     //I had attempted setting the CSS Class for the div that would have set
  7.     //opacity of it, but this isn't working well with the asynchronous stuff in IE
  8.     //so I decided to set each individual style in JavaScript instead
  9.     //shield.className = 'modalBackground';
  10.  
  11.     shield.style.backgroundColor='white';
  12.     shield.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=50, FinishOpacity=0, Style=2)';
  13.     shield.style.opacity='.5';
  14. }
The following works but I'm don't think it will work in IE6:
Expand|Select|Wrap|Line Numbers
  1. function Processing() {    
  2.     var shield = document.getElementById('ctl00_CPH_MainContent_myControl_shield');
  3.     shield.style.display = 'block';   
  4.     //shield.className = 'modalBackground';   
  5.     shield.style.backgroundColor='white';     
  6.     shield.style.filter = 'alpha(opacity=50)';    
  7.     shield.style.opacity='.5'; 
  8. }
Thanks for your time,

-Frinny
Feb 17 '09 #1
3 1815
acoder
16,027 Expert Mod 8TB
The element needs to "have layout" in IE for it to work. See here for more on the hasLayout property.
Feb 18 '09 #2
Frinavale
9,735 Expert Mod 8TB
An interesting read.

My initial thought on the topic is: "Got Layout?"

That article actually answered a long forgotten question regarding determining the height and width (clientWidth/clientHeight) of an element in order to center it via JavaScript...I just gave up on the problem and worked around it but I think I'll revisit that code and make appropriate changes to it...thanks.

But, this article didn't help me in figure my Opacity issue.
My element has it's height and width set, it hasLayout, and the opacity is "sort of" working...

Maybe I'll just give up on the IE6 compatibility. It's almost 2 versions ago...and is so much more work! Sometimes IE really gets on my nerves....but no where near as much as Opera.

-Frinny
Feb 18 '09 #3
acoder
16,027 Expert Mod 8TB
Have you got a standalone version of IE6? If so, filters may not work.
Feb 23 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
0
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...
0
by: Muhammad Aftab Alam | last post by:
Hello All I am using DotNet classes in my MFC Application. now that I have successfully used some DotNET classes and more over Form Classes as well I want to set the Opacity of my MFC Dialog using...
1
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...
0
by: Mark Denardo | last post by:
Can someone tell me why setting the opacity of a control in 2005 no longer works like it did in 2003 (using Color.FromArgb)? In 2003, I could make the opacity of the text of a Label 50% by the...
2
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...
15
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.