use setTimeout not setInterval
Code:
<!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" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<input type="button" name="" value="Fly Down" onclick="flyDown('dmenudiv',1,300);"/><input type="button" name="" value="Fly Up" onclick="flyDown('dmenudiv',-1,100);"/>
<div id="dmenudiv" style="height:100px;width:400px;background-Color:red;" ></div>
<script type="text/javascript">
/*<![CDATA[*/
function flyDown(id,ud,e){
var x=document.getElementById(id);
if (x){
clearTimeout(x.to);
var y=parseInt(x.style.height)+ud;
if((ud>0&&y<e)||(ud<0&&y>e)){
x.style.visibility='visible';
x.style.height = y+'px';
if(y<150){
x.style.top = y+'px';
}
x.style.zIndex='100';
x.to = setTimeout(function(){flyDown(id,ud,e)}, 75);
}
else{
x.style.height = e+'px';
alert('here in clear');
// stopexpand();
// document.getElementById('opaque').style.display='block';
}
}
}
/*]]>*/
</script>
</body>
</html>
Bookmarks