当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript中对对层的控制

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javascript中对对层的控制


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 136 ::
收藏到网摘: n/a

层的开发在实际应用中比较重要,比如漂浮广告等等,我这里简单探讨一下。
1. 控制层的显示或隐藏
两种办法,其实都是控制样式的。
办法一:控制 display 属性
<script language="javascript">
function show(status)
{
document.getElementById("div1").style.display = status;
}
</script>
<div id="div1" style="left:10px;top:200px;width:250;height:100;z-index:2;">
这是一层,能看见吗,呵呵.
</div>
<a href=# onClick="show('block');">显示</a>
<a href=# onClick="show('none')">关闭</a>

办法二 控制 visibility 属性
<script language="javascript">
function show(status)
{
document.getElementById("div1").style.visibility = status;
}
<div id="div1" style="left:10px;top:200px;width:250;height:100;z-index:2;visibility=hideen;">
这是一层,能看见吗,呵呵.
</div>
<a href=# onClick="show('visible);">显示</a>
<a href=# onClick="show('hidden')">关闭</a>

如果要控制层定时关闭的话,可以加上:
function setTimeStart()
10 {
11 window.setTimeout(hiddenTips,4000);
12 }^
</script>
上面代码就是利用setTimeout方法来控制4秒后关闭层。

2. 控制层的运动,类似于浮动广告
主要就是通过控制层样式中的top和left属性的值来运动,通过随机生成不同的值,看起来就象在运动一样。
<script language="javascript">
var a=200, b=100;
var c=0.1;
var d=5;
var t=0;
function float_1()
{
var random1 = 100*Math.random();
var random2 = 100*Math.random();
var float_1 = document.all ? document.all.float_1.style : document.float_1;
float_1.left = Math.round(a*Math.cos(t)*Math.cos(t/d)+a)+random1;
float_1.top = Math.round(b*Math.sin(t)+b)+random2;
t+=c;
setTimeout("float_1()", 500);
}
</script>
</head>

<body onLoad="float_1()"><div id="float_1" style="position:absolute;width:200;height:100;z-index:2;visibility:visible">
让我动起来。
</div>
</body>
通过 setTimeout方法进行调用,每隔多少秒运行一次,达到一直运动的目的。