是这种效果吗 <script language="javascript"> var step = 1; var timer,timer2; var begin,end; function zoom(type) { if (type == "in") step = 1; if (type == "out") step = -1; ice.style.pixelWidth += step; ice.style.pixelHeight += step; timer = setTimeout("zoom('"+type+"')",10); } function stopZoom() { clearTimeout(timer); } function zoom2(type) { if (type == "in") { ice.style.pixelWidth *= 2; ice.style.pixelHeight *= 2; } if (type == "out") { ice.style.pixelWidth /= 2; ice.style.pixelHeight /= 2; } } function startTimer(type) { var d = new Date(); begin = d.getTime(); timer2 = setTimeout("endTimer('"+type+"')",10); } function endTimer(type) { var d = new Date(); end = d.getTime(); //alert(end); if ((end - begin) > 500) //1000ms { clearTimeout(timer2); zoom(type); } else timer2 =setTimeout("endTimer('"+type+"')",10); } function setZoom(type) { var d = new Date(); var up = d.getTime(); if (up - begin > 500) {
<script language="javascript">
var step = 1;
var timer,timer2;
var begin,end;
function zoom(type)
{
if (type == "in")
step = 1;
if (type == "out")
step = -1;
ice.style.pixelWidth += step;
ice.style.pixelHeight += step;
timer = setTimeout("zoom('"+type+"')",10);
}
function stopZoom()
{
clearTimeout(timer);
}
function zoom2(type)
{
if (type == "in")
{
ice.style.pixelWidth *= 2;
ice.style.pixelHeight *= 2;
}
if (type == "out")
{
ice.style.pixelWidth /= 2;
ice.style.pixelHeight /= 2;
}
}
function startTimer(type)
{
var d = new Date();
begin = d.getTime();
timer2 = setTimeout("endTimer('"+type+"')",10);
}
function endTimer(type)
{
var d = new Date();
end = d.getTime();
//alert(end);
if ((end - begin) > 500) //1000ms
{
clearTimeout(timer2);
zoom(type);
}
else
timer2 =setTimeout("endTimer('"+type+"')",10);
}
function setZoom(type)
{
var d = new Date();
var up = d.getTime();
if (up - begin > 500)
{
stopZoom();
}
else
{
clearTimeout(timer2);
zoom2(type);
}
}
</script>
<body>
<center>
<input type=button value='放大' onmousedown="startTimer('in')" onmouseup="setZoom('in')">
<input type=button value='缩小' onmousedown="startTimer('out')" onmouseup="setZoom('out')">
<div id='ice' style='width:100px;height:100px;background:#AA0000'>
</div>
</center>
</body>
onmousedown="timer1=setInterval('mypic.width++;',30)"
onmouseup="clearInterval(timer1)">
<input type="button" value="-"
onmousedown="timer1=setInterval('mypic.width--;',30)"
onmouseup="clearInterval(timer1)">
<br>
<img src="http://community.csdn.net/images/csdn.gif" id="mypic">