![]() Topic awaiting preservation: June 2005 - 20 lines JavaScript contest - Opacity demo (Page 1 of 1) |
|
|---|---|
|
Bipolar (III) Inmate From: London |
posted 06-04-2005 15:02
I thought I'd do something a bit different this month. I'd like to see what good uses people can come up with for opacity. It can be anything from a game, to a demo, to a utility... as long as it demonstrates a good working use of opacity. quote:
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Simple cross-browser opacity demo</title>
<style type="text/css">
div {
position: absolute;
width: 200px;
height: 200px;
}
#div1 {
background-color: blue;
top: 50px;
left: 50px;
}
#div2 {
background-color: red;
top: 100px;
left: 100px;
}
</style>
<script type="text/javascript">
<!--
function setOpacity(element, opacity) {
// In NN / Moz, when opacity is 100, flickering occurs. If the opacity is reduced to 99.99, this does not happen.
// This code will achieve this, if uncommented
// if (opacity == 100 && (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1)) opacity = 99.99;
// Set CSS 3, Moz, NN, FF, gecko, Konqueror, Safari
element.style.opacity = element.style.MozOpacity = element.style.KhtmlOpacity = opacity / 100;
// Set IE
element.style.filter = 'alpha(opacity=' + opacity + ')';
}
//-->
</script>
</head>
<body onload="setOpacity(document.getElementById('div2'), 50);">
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
|
|
Paranoid (IV) Inmate From: USA |
posted 06-04-2005 22:23
*recycle* |
|
Bipolar (III) Inmate From: Cranleigh, Surrey, England |
posted 06-05-2005 02:01
Hmm...my IE seems to be screwed - it won't do alpha filters full stop. But then, it won't even access the internet - it's completely screwed. Anyway, I was just sticking the demo commands together in preparation for an entry, but now I don't know if it works in IE :\. Could anyone test for me by any chance? |
|
Bipolar (III) Inmate From: Sweden |
posted 06-06-2005 00:24
Wrayal: Nope, it didn't work when I tested it like this: code: <html>
<body>
<div style="background-color:blue">
<div id="test" style="background-color:red">Hello</div> there
</div>
<script>
function setOpacity(element, opacity) {(navigator.userAgent.indexOf('IE')!=-1)?element.style.filter = 'alpha(opacity=' + opacity + ')':(opacity == 100 && (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1))?element.style.opacity = element.style.MozOpacity = element.style.KhtmlOpacity=99.99/100:element.style.opacity = element.style.MozOpacity = element.style.KhtmlOpacity=opacity/100}
setOpacity(document.getElementById('test'),50)
</script>
</body>
</html>
|
|
Bipolar (III) Inmate From: Cranleigh, Surrey, England |
posted 06-06-2005 09:41
Yes, sorry, that should have beee the first thing I wrote - cool topic! |
|
Paranoid (IV) Inmate From: France |
posted 06-06-2005 10:40
|
|
Bipolar (III) Inmate From: London |
posted 06-20-2005 22:45
Ooooooooooooooh. I just can't wait |
|
Bipolar (III) Inmate From: London |
posted 06-30-2005 20:02
While we have an entry, how would people feel about extending this by another few days / weeks to allow for other people to enter? |
|
Paranoid (IV) Inmate From: France |
posted 07-01-2005 11:52
|
|
Bipolar (III) Inmate From: London |
posted 07-05-2005 08:22
Not to worry - I'm sure there will be plenty of other opportunities for great entries. |
|
Paranoid (IV) Inmate From: USA |
posted 07-07-2005 21:21
haha, thanks! |