1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| <html>
<head>
<title>Opacity modifier</title>
<script><!--
getLocation=function(node) {
var loc = {"width":node.offsetWidth,"height":node.offsetHeight };
var left=node.offsetLeft;
var top =node.offsetTop;
while(node.offsetParent) {
node=node.offsetParent;
left+=node.offsetLeft;
top +=node.offsetTop;
}
loc.left=left;
loc.top=top;
return loc;
}
addOpacityChangeEffect=function(node) {
node.oo = document.createElement("div");
node.oo.style.backgroundColor="black";
node.oo.style.position="absolute";
node.oo.opacity=25;
node.oo.opacityModifier=0;
node.oo.onmouseover=function() {
this.opacityModifier=-1;
}
node.oo.onmouseout=function() {
this.opacityModifier=1;
}
node.oo.update=function(node) {
var loc=getLocation(node);
this.style.left=loc.left+"px";
this.style.width=loc.width+"px";
this.style.top=loc.top+"px";
this.style.height=loc.height+"px";
this.opacity+=this.opacityModifier;
if (this.opacity>25) {this.opacity=25;}
if (this.opacity<0) {this.opacity=0;}
this.style.opacity=(this.opacity/100);
this.style.filter="alpha(opacity="+this.opacity+")"
var zi = parseInt(node.style.zIndex);
if (zi < 0) { zi = 0 }
zi+=1;
this.style.zIndex=zi;
}
setInterval(function() { node.oo.update(node); }, 1);
document.body.appendChild(node.oo);
}
--></script>
</head>
<body>
<img id="image1" src="fremycompany.jpg"/>
<script>addOpacityChangeEffect(document.getElementById("image1"));</script>
</body>
</html> |