1 Star 0 Fork 0

bendell02/javascript_tutorial

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example13.5.html 3.00 KB
一键复制 编辑 原始数据 按行查看 历史
bendell02 提交于 2019-08-28 21:08 +08:00 . Update example13.5.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Encapsulating</title>
<style type="text/css">
div {
position: absolute;
top: 30px;
left: 50px;
}
#div2 {
opacity: 0.0; filter: alpha(opacity=0);
}
/*
#div1 img {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=example9.12_fig01.png, sizingMethod='scale');
}
#div2 img {
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=example9.12_fig02.png, sizingMethod='scale');
}*/
</style>
<script type="text/javascript">
//<![CDATA[
var theobjs = new Array();
function DivObj(obj) {
this.obj = obj;
this.getAlphaOpacity = function() {
var fltr = this.obj.style.filter;
var indx1 = fltr.indexOf("opacity=");
var indx2 = fltr.indexOf("");
fltr = fltr.substring(indx1+8, indx2) / 100;
return fltr;
}
this.getCSSOpacity = function() {
return parseFloat(this.obj.style.opacity);
}
// this.objGetOpacity = (this.obj.style.filter === undefined) ? this.getCSSOpacity : this.getAlphaOpacity;
this.objGetOpacity = this.getCSSOpacity;
this.alphaOpacity = function(value) {
var opacity = value*100;
this.obj.style.filter = "alpha(opacity=" + opacity + ")";
}
this.cssOpacity = function(value) {
this.obj.style.opacity = ""+value;
}
// this.objSetOpacity = (this.obj.style.filter === undefined) ? this.cssOpacity : this.alphaOpacity;
this.objSetOpacity = this.cssOpacity;
}
window.onload = function() {
theobjs["div1"] = new DivObj(document.getElementById("div1"));
theobjs["div2"] = new DivObj(document.getElementById("div2"));
theobjs["div1"].objSetOpacity(1.0);
theobjs["div2"].objSetOpacity(0.0);
}
document.onclick = function() {
// fade-out the div1
var currentOpacity = theobjs["div1"].objGetOpacity();
if (currentOpacity <= 0) {
document.onclick = null;
return;
}
currentOpacity -= 0.1;
theobjs["div1"].objSetOpacity(currentOpacity);
// display div2
currentOpacity = theobjs["div2"].objGetOpacity();
currentOpacity += 0.1;
theobjs["div2"].objSetOpacity(currentOpacity);
}
//]]>
</script>
</head>
<body>
<div id="div1">
<img src="example9.12_fig01.png" alt="" />
</div>
<div id="div2">
<img src="example9.12_fig02.png" alt="" />
</div>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bendell02/javascript_tutorial.git
git@gitee.com:bendell02/javascript_tutorial.git
bendell02
javascript_tutorial
javascript_tutorial
master

搜索帮助