473,659 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gradual opacity control via JS?

The following style sets the opacity or semi-transparency in Mozilla and
Explorer browsers for an image:

#myImage{
filter: alpha(opacity=5 0); -moz-opacity:0.50; opacity: 0.50;
}

<img src="someimage. jpg" name="myImage" id="myImage">

The alpha(opacity=5 0 does it in IE and the opacity: 0.50 does it Mozilla.
I'm not sure what purpose -moz-opacity:0.50 serves, as it seems to work
without that, at least on the version Mozilla 1.7.6 I've tested it on.

Naturally it is possible to change a background image by for example:

document.getEle mentById("myIma ge").style.back ground="url(ano therimage.jpg)" ;

Or a normal image:

document.images .myImage.src='a notherimage.jpg ';

Is it possible to gradually replace one image with another by use of opacity
in stages (timeouts), achieve the effect of a typical Flash animation
fade-in fade-out animation, replacing the need of Flash for that. Perhaps
it can be done by combining background and foreground images by timeouts?

The alpha/opacity is as far as I know proprietary IE and Mozilla
non-standard CSS methods, so in any case it couldn't work on all browsers.
Any ideas if and how this could be done would be much appreciated.

Thanks
Nov 23 '05 #1
5 2904
Hi all...

First of all thanks for the code you have provided..

try this code which gives the fade in fade out effect with the
timer....
<script>
<!-- Initial Opacity -->
var Opacity=10;
var flag;

function y(Opacity)
{

var Obj = document.getEle mentById('myIma ge')

var str ='alpha(opacity ='+Opacity+')';

Obj.style.filte r = str;
<!-- Recursive Call -->
x();

}

function x(){

if( Opacity > 100 )
flag = 1;

if(z<0)
flag = 0;

if(flag)
Opacity -= 5; <!-- For the Fade out Effect -->
else
Opacity += 5; <!-- For the Fade in Effect -->

var str = 'y('+ z +')';
setTimeout(str, 100);

}
</script>

<form onload='x()'>

</form>

For more Information check this link
http://www.markup.co.nz/dom/style_the_dom.htm

Nov 23 '05 #2
<script>
var z=10;
var flag;

function y(z){
var Obj = document.getEle mentById('myIma ge')
var str ='alpha(opacity ='+z+')';
Obj.style.filte r = str;
x();
}
function x(){
if(z>100)
flag = 1;
if(z<0)
flag = 0;
if(flag)
z -= 5;
else
z += 5;
var str='y('+z+')';
setTimeout(str, 100);
}
</script>

<style>
#myImage{
filter: alpha(opacity=1 0);
}

</style>

Nov 23 '05 #3
James wrote on 17 nov 2005 in comp.lang.javas cript:
if(z>100)
flag = 1;
if(z<0)
flag = 0;
if(flag)
z -= 5;
else
z += 5;


var incDec = 5;
var z = 10;
..........
incDec = (z>100)?-5:(z<0)?5:incDe c;
z += incDec;
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #4
> First of all thanks for the code you have provided..

Thank you for the example. I will test your code. In the meantime I also
found an interesting page on the topic:
http://www.brainerror.net/scripts_js_blendtrans.php
(see the heading "Fading one image into another")

The page explains that "-moz-opacity:" is only for older Mozilla's and that
"opacity:" is the official CSS.

I use an up-to-minute konqueror browser on Linux where the CSS3 standard
"opacity:" is not working, yet I think it works on OSX. But interestingly
there is also a "-khtml-opacity". Thanks again for the example code.
Nov 23 '05 #5
James wrote:
<script>
[...]
</style>


I can't get this code running. Did you test run it?
Nov 23 '05 #6

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

Similar topics

3
10217
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...
1
9155
by: Mac | last post by:
Hello, pictureBox does not have an opacity property so anyone knows how can someone create the same effect on a picture box? Is it possible at all or what? I will then need to inheritate a component from picture box for my purpose but I don't seem to be able to find a way to do this opacity thing.
1
4957
by: marfi95 | last post by:
Hi all. I have some forms that use the opacity property to fade in/out. I'd like to do the same kind of thing with a richtextbox on one of my forms. Doesn't look like opacity is exposed on the rtb control, so I was wondering if anyone had done this before. I'm looking for the effect of fading in at a specific point in the form (when a timer ticks actually). I also don't mind some effect like the size of the control starting smaller...
4
7682
by: beaker | last post by:
Hello, Is there a way to alter the opacity of an MDI child window? I've tried setting the Opacity property, but it has no effect on the children (fine for the parent though). (I want to write an app where I can open several images in child forms, resize them and manually overlay them on top of each other, and control the transparency so I can fade from one to the other to visually compare them).
3
1724
by: VB Programmer | last post by:
I have a form which has an opacity control of type numbericupdown. It's supposed to control the opacity of frmMain. Here's my code... Private Sub numOpacity_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numOpacity.ValueChanged frmMain.Opacity = Me.numOpacity.Value End Sub This doesn't seem to work at all. Any suggestions?
12
3772
by: Patrick Dugan | last post by:
I know that I can change the opacity of an entire form, but is there a way to control opacity to specific controls or components? For example I want to create a form that is semi-transparent (maybe looks like a sheet of green glass) but has elements or graphics on top that I want to be opaque. Perhaps I want the sheet of glass to have writing or other graphics "painted" on the surface. Is there some way to mix varying transparencies...
2
2343
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
3710
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
8332
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,...
1
8525
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
8627
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
7356
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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 we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.