<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>具有缓冲效果的可伸缩显隐层</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<script language="javascript">
var flag=0;
function f_s(id){
var obj=document.getElementById(id);
obj.style.display="block";
obj.style.height="1px";
var changeW=function(){
var obj_h=parseInt(obj.style.height); //以十进制解析 obj.style.height
if(obj_h<=335){
obj.style.height=(obj_h+Math.ceil((335-obj_h)/10))+"px"; //Math.ceil返回大于大于等于(335-obj_h)/10)的最小整数
}
else{
clearInterval(bw1);
}
}
bw1= setInterval(changeW,1);
if(flag>0){
clearInterval(bw2);
}
}
function closeW(id){
flag++;
var obj=document.getElementById(id);
var closeDiv=function(){
clearInterval(bw1);
var obj_h=parseInt(obj.style.height);
if(obj_h>1){
obj.style.height=(obj_h-Math.ceil(obj_h)/10)+"px";
}
else{
clearInterval(bw2);
obj.style.display="none";
}
}
bw2= setInterval(closeDiv,1);
//alert(flag)
}
function showDiv(){
var ele = document.getElementById("div1");
clearInterval(bw1);
clearInterval(bw2);
ele.style.display = "block";
ele.style.height = 335 + "px";
}
</script>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div onmouseover="f_s('div1')" onmouseout="closeW('div1')" style="position:absolute;background:black;left:200px;top:34px;width:149px;height:35px;"></div>
<div id="div1" onmouseover="showDiv()" onmouseout="closeW('div1')" style="position:absolute;background:aqua;left:200px;overflow:hidden;top:70px;width:349px;display:none;">
dfsdfsdf 我是
</div>
</body>
</html>
这是一个js控制div层的页面,谁能给我讲讲这段代码中 setinerval 的作用是什么?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>具有缓冲效果的可伸缩显隐层</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<script language="javascript">
var flag=0;
function f_s(id){
var obj=document.getElementById(id);
obj.style.display="block";
obj.style.height="1px";
var changeW=function(){
var obj_h=parseInt(obj.style.height); //以十进制解析 obj.style.height
if(obj_h<=335){
obj.style.height=(obj_h+Math.ceil((335-obj_h)/10))+"px"; //Math.ceil返回大于大于等于(335-obj_h)/10)的最小整数
}
else{
clearInterval(bw1);
}
}
bw1= setInterval(changeW,1);
if(flag>0){
clearInterval(bw2);
}
}
function closeW(id){
flag++;
var obj=document.getElementById(id);
var closeDiv=function(){
clearInterval(bw1);
var obj_h=parseInt(obj.style.height);
if(obj_h>1){
obj.style.height=(obj_h-Math.ceil(obj_h)/10)+"px";
}
else{
clearInterval(bw2);
obj.style.display="none";
}
}
bw2= setInterval(closeDiv,1);
//alert(flag)
}
function showDiv(){
var ele = document.getElementById("div1");
clearInterval(bw1);
clearInterval(bw2);
ele.style.display = "block";
ele.style.height = 335 + "px";
}
</script>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div onmouseover="f_s('div1')" onmouseout="closeW('div1')" style="position:absolute;background:black;left:200px;top:34px;width:149px;height:35px;"></div>
<div id="div1" onmouseover="showDiv()" onmouseout="closeW('div1')" style="position:absolute;background:aqua;left:200px;overflow:hidden;top:70px;width:349px;display:none;">
dfsdfsdf 我是
</div>
</body>
</html>
这是一个js控制div层的页面,谁能给我讲讲这段代码中 setinerval 的作用是什么?
解决方案 »
- 第三次发帖:JQuery如何实现QQ音乐播放器图片特效?
- 救命啊, 加载页面,点击到其中一模块页面就出现在那块。
- 限制一个输入框只能输入0到1且最多只能输入三位小数。用JS。
- 为什么vbscrip和javascrip返回不一样?
- 1st JavaScript Editor Pro 中,调试时,funcion中的的语句不能识别?
- 有时间过来看看,有点挑战性的题目,怎样同时获得动态取值...
- 找不到问题所在,时而报错时而不错。什么原因?
- 如何取文本框的长度,并取最后一个值????(在线)
- 请帮忙:怎样用代码实现当选中或经过表格行时被选中或向下的效果(像按钮被按下的那种效果!)
- 怎样刷新页面的某一部分,而不是全部刷新?
- 一个简单的验证问题
- 图片点击事件为什么执行了7次之后就不执行了?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>具有缓冲效果的可伸缩显隐层 </title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到 <head>与 </head>之间-->
<script language="javascript">
var flag=0;
function f_s(id){
var obj=document.getElementById(id);
obj.style.display="block";
obj.style.height="1px";
var changeW=function(){
var obj_h=parseInt(obj.style.height); //以十进制解析 obj.style.height
if(obj_h <=335){
obj.style.height=(obj_h+Math.ceil((335-obj_h)/10))+"px"; //Math.ceil返回大于大于等于(335-obj_h)/10)的最小整数
}
else{
clearInterval(bw1); //销毁bw1,停止增加DIV的高度
}
}
bw1= setInterval(changeW,1); //每隔1毫秒执行changeW
if(flag>0){
clearInterval(bw2); //销毁bw2,停止减小DIV的高度
}
}
function closeW(id){
flag++;
var obj=document.getElementById(id);
var closeDiv=function(){
clearInterval(bw1); //销毁bw1,停止增加DIV的高度
var obj_h=parseInt(obj.style.height);
if(obj_h>1){
obj.style.height=(obj_h-Math.ceil(obj_h)/10)+"px"; //减小DIV高度
}
else{
clearInterval(bw2); //销毁bw2,停止减小DIV的高度
obj.style.display="none";
}
}
bw2= setInterval(closeDiv,1); //每隔1毫秒执行closeDiv
//alert(flag)
}
function showDiv(){
var ele = document.getElementById("div1");
clearInterval(bw1);
clearInterval(bw2);
ele.style.display = "block";
ele.style.height = 335 + "px";
}
</script>
</head>
<body>
<!--把下面代码加到 <body>与 </body>之间-->
<div onmouseover="f_s('div1')" onmouseout="closeW('div1')" style="position:absolute;background:black;left:200px;top:34px;width:149px;height:35px;"> </div>
<div id="div1" onmouseover="showDiv()" onmouseout="closeW('div1')" style="position:absolute;background:aqua;left:200px;overflow:hidden;top:70px;width:349px;display:none;">
dfsdfsdf 我是
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function opendiv(id){
var div = document.getElementById(id);
div.style.display = "block";
}
function closediv(id){
var div = document.getElementById(id);
div.style.display = "none";
}
</script>
<style type="text/css">
.one{
width:100px;
height:50px;
background:#039;
}
.two{
width:500px;
height:200px;
position:absolute;
left:10%;
top:80px;
background:#F33;
display:none;
}
</style>
</head><body>
<center>
<div id="one" class="one" onmouseover="opendiv('two')" onmouseout="closediv('two')"></div>
<div id="two" class="two" onmouseover="opendiv('two')" onmouseout="closediv('two')"></div>
</center>
</body>
</html>
<div id="one" class="one" onmouseover="opendiv('two')" onmouseout="closediv('two')"> </div>
<div id="two" class="two" onmouseover="opendiv('two')" onmouseout="closediv('two')"> </div>
在鼠标离开id为one的div时 id为two的div就消失了,鼠标无法移动到id为two的div上面有什么方法可以解决么?
设计这种效果时,一般情况下,one和two要“接壤”
这样鼠标可以从one直接移到two,而two也不会消失
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档 </title>
<script type="text/javascript">
function opendiv(id){
var div = document.getElementById(id);
div.style.display = "block";
}
function closediv(id){
var div = document.getElementById(id);
div.style.display = "none";
}
</script>
<style type="text/css">
.one{
width:100px;
height:50px;
background:#039;
}
.two{
width:500px;
height:200px;
position:absolute;
left:10%;
top:64px;
background:#F33;
display:none;
}
</style>
</head> <body>
<center>
<div id="one" class="one" onmouseover="opendiv('two')" onmouseout="closediv('two')"> </div>
<div id="two" class="two" onmouseover="opendiv('two')" onmouseout="closediv('two')"> </div>
</center>
</body>
</html>