|
 
升级   11.67% - 注册时间
- 2006-2-6
- 威望
- 134
- 阅读权限
- 30
- 积分
- 235
- 帖子
- 113
- 精华
- 0
- UID
- 46652
- 状态
- 当前离线
|
这是我自己写的一个,本来想做成一个钟摆的,就是用鼠标拉到某个位置后,自动掉下来,
按照能量守恒定律进行力学摆动。
但是因为公式不知道,还有一些莫名的数学BUG,实在写不下去了,请高手帮忙修改!!
- <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <!--[if !mso]>
- <style>
- v\:* { behavior: url(#default#VML) }
- o\:* { behavior: url(#default#VML) }
- .shape { behavior: url(#default#VML) }
- </style>
- <![endif]-->
- <style>
- #div{
- position:absolute;
- width:50px;
- height:50px;
- border:1px #333 solid;
- background-color:#666699;
- color:#FFF;
- cursor:pointer;
- filter: progid:DXImageTransform.Microsoft.Matrix(M11=1,M12=0,M21=0,M22=1,SizingMethod="auto expand");
- z-index:2;
- font-size:16px;
- text-align:center;
- line-height:50px;
- overflow:hidden;
- }
- #line{
- position:absolute;
- left:0;
- top:0;
- z-index:1;
- }
- </style>
- <script language="javascript">
- var div=null;
- var line=null;
- function config()
- {
- div=document.getElementById("div");
- line=document.getElementById("line");
-
- div.width=parseInt(div.currentStyle.width);
- div.height=parseInt(div.currentStyle.height);
- div.q=0;
-
- line.strokecolor="#000";
- line.strokeweight="1px";
- line.from="200,200";
- line.to="200,300";
- line.pleft=300;
- line.ptop=200;
- line.plength=200;
-
- line.from=line.pleft+","+line.ptop;
-
- document.body.onselectstart=function(){event.returnValue=false;};
- div.setpos=div_setpos;
- div.setrote=div_setrote;
- div.setpos(0,200,true);
- div.setpos(200,200);
- div.setrote();
-
- div.onmousedown=div_onmousedown;
- div.onmousemove=div_onmousemove;
- div.onmouseup=div_onmouseup;
-
- }
- function div_onmousedown()
- {
- div.setCapture();
- div.preleft=div.xleft;
- div.pretop=div.xtop;
- div.prex=event.x;
- div.prey=event.y;
- }
- function div_onmousemove()
- {
- if(event.button!=1)
- return;
- var x=event.x-div.prex+div.preleft;
- var y=event.y-div.prey+div.pretop;
- div.setpos(x,y);
- }
- function div_onmouseup()
- {
- div.releaseCapture();
- }
- function div_setrote()
- {
-
- }
- function div_setpos(xleft,xtop,byhand)
- {
- div.xleft=xleft;
- div.xtop=xtop;
- if(byhand==true){
- div.style.left=line.pleft+xleft-div.width/2;
- div.style.top=line.ptop+xtop-div.height/2;
- line.to=parseInt(div.style.left)+div.width/2+","+parseInt(div.style.top);
- }else{
- var qa=0;
- if(xtop==0){
- qa=Math.PI/2;
- }else{
- qa=Math.atan(xleft/xtop);
- }
- var lx=Math.abs(parseInt((div.width/2)*Math.cos(qa)));
- var ly=Math.abs(parseInt((div.width/2)*Math.sin(qa)));
- if(xleft>=0){
- div.style.left=line.pleft+xleft-lx;
- div.style.top=line.ptop+xtop-ly;
- line.to=(line.pleft+xleft)+","+(line.ptop+xtop);
- }else{
- var x1=Math.abs(div.width*Math.tan(qa));
- var x2=div.height-x1;
- var w2=x2*Math.sin(qa);
- var w1=x1/Math.sin(qa);
- var w=Math.abs(w1)+Math.abs(w2);
- div.style.left=line.pleft+xleft-(w-lx);
- div.style.top=line.ptop+xtop-ly;
- line.to=(line.pleft+xleft)+","+(line.ptop+xtop);
- }
- with(div.filters.item(0)){
- M11=Math.cos(qa);
- M12=Math.sin(qa);
- M21=-Math.sin(qa);
- M22=Math.cos(qa);
- }
-
- }
- }
- window.attachEvent("onload",config);
- </script>
- </head>
- <body>
- <div id="div">重</div>
- <v:line id="line"></v:line>
- </body>
- </html>
复制代码运行代码另存代码 |
|