日期:2014-05-16  浏览次数:20471 次

平滑拖动,高人帮着改下?
<html>
    <head>
        <title> My   JSP   'test.jsp '   starting   page </title>
<script   type= "text/javascript ">
var   mX;
var   mY;
var   flag=0;
function   mousedown()
{
mX=event.clientX;
mY=event.clientY;
flag=1;
}
function   mouseup()
{
flag=0;
}
function   mousemove()
{
if(flag==0)return   false;
var   e=document.getElementById( 'aa ');
mXmov=event.clientX;
mYmov=event.clientY;
var   w=e.offsetWidth;
e.style.width=w+(mXmov-mX);
}
</script>
<style   type= "text/css ">
div{float:left;}
.aaCss{border:1px   solid   red;width:200px;height:100px;}
</style>
    </head>
   
    <body>
        <div   id= "body "   onmouseup= "mouseup() ">
        <div   id= "aa "   class= "aaCss "> AAAA </div>
        <div   onmousedown= "mousedown() "   onmousemove= "mousemove() "   id= "bb "   style= "width:30px;border:1px   solid   gary; "> dragMe </div>
        </div>
    </body>
</html>
=====================================================

这个拖动框为什么一跳一跳的.如何平滑的拖动,要怎么改代码?

------解决方案--------------------
<html>
<head>
<title> My JSP 'test.jsp ' starting page </title>
<script type= "text/javascript ">
var mX;
var mY;
var flag=0;
function get_x(){
mX=event.x;
mY=event.y;
}
function mousedown()
{
mX=event.x;
mY=event.y;
flag=1;
}
function mouseup()
{
flag=0;
}
function mousemove()
{
if(flag==0)return false;
var e=document.getElementById( 'aa ');
mXmov=event.clientX;
mYmov=event.clientY;
var w=e.offsetWidth;
e.style.width=parseInt(w)+parseInt(mXmov-mX);
}
</script>
<style type= "text/css ">
div{float:left;}
.aaCss{border:1px solid red;width:200px;height:100px;}
</style>
</head>

<body onmousemove= "get_x() ">
<div id= "body " onmouseup= "mouseup() ">
<div id= "aa " class= "aaCss "> AAAA </div>
<div onmousedown= "mousedown() " onmousemove= "mousemove() " id= "bb " style= "width:30px;border:1px solid gary; "> dragMe </div>
</div>
</body>
</html>