一个javascript的问题 层的扩展与收缩 请帮忙 回答详细的 再送20分以表谢意

来源:百度知道 编辑:UC知道 时间:2024/06/11 10:35:08
<script>
var act
function over(id,maxlen){
var obj=document.getElementById(id);
var h=parseInt(obj.offsetHeight);
if(h<maxlen){
obj.style.height=h+2;
clearTimeout(act);
act=setTimeout("over('"+id+"',"+maxlen+")",10);}
}
function out(id,minlen){
var obj=document.getElementById(id);
var h=parseInt(obj.offsetHeight);
if(h>minlen){
obj.style.height=h-2;
clearTimeout(act);
act=setTimeout("out('"+id+"',"+minlen+")",20);}
}
</script>

<div id="abc" onMouseover="over('abc',100);" onMouseout="out('abc',20);"

style="background:#eee;">大家 好 这是一个javascript实例</div><br>

<div id="mytd" onmouseover="over('my

<script>
var ov
var ou //改动1:把展开和收缩分开。

function over(id,maxlen){
var obj=document.getElementById(id);
var h=parseInt(obj.offsetHeight);
if(h<maxlen){
obj.style.height=h+2; //改动2:不需要作用clearTimeout在这里。
ov=setTimeout("over('"+id+"',"+maxlen+")",10);
}
}
function out(id,minlen){
clearTimeout(ov)//改动3:清除OV,不改变ou
var obj=document.getElementById(id);
var h=parseInt(obj.offsetHeight);
if(h>minlen){
obj.style.height=h-2;
ou=setTimeout("out('"+id+"',"+minlen+")",20);
}
}
</script>

<div id="abc" onMouseover="over('abc',100);" onmouseleave="out('abc',20);"

style="background:#eee;">大家 好 这是一个javascript实例</div><br> <!--改动4:把onmouseout 换成了onmouseleave 再试试看 哪个更好-->