您好,欢迎访问一九零五行业门户网

html的拖拽动画实现方法

我们知道,用html来实现动画的方法有很多,这次教大家如何用js来实现html里的拖拽动画,我们一起看一下案列。
<!doctype"> <html"> <head> <style> #p1 {width:100px; height:100px; background:red; position:absolute;} </style> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> var odiv=null; var disx=0; var disy=0; window.onload=function () { odiv=document.getelementbyid('p1'); odiv.onmousedown=fndown; }; function fndown(ev) { var oevent=ev||event; disx=oevent.clientx-odiv.offsetleft; disy=oevent.clienty-odiv.offsettop; document.onmousemove=fnmove; document.onmouseup=fnup; } function fnmove(ev) { var oevent=ev||event; odiv.style.left=oevent.clientx-disx+'px'; odiv.style.top=oevent.clienty-disy+'px'; } function fnup() { document.onmousemove=null; document.onmouseup=null; } </script> </head> <body> <p id="p1"> </p> </body> </html>
相信看了这些案例你已经掌握了方法,更多精彩请关注其它相关文章!
相关阅读:
js代码案列-根据日期计算星期几
js引擎运行时是什么样的
h5中的弹窗无法用webview弹出怎么解决
以上就是html的拖拽动画实现方法的详细内容。
其它类似信息

推荐信息