zoukankan      html  css  js  c++  java
  • jq-demo-拖拽

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6         <style>
     7             #box{
     8                  100px;
     9                 height: 100px;
    10                 background: red;
    11                 position: absolute;
    12                 left: 20px;
    13                 top: 20px;
    14             }
    15         </style>
    16     </head>
    17     <body>
    18         <div id = "box"></div>
    19         
    20         <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    21         <script type="text/javascript">
    22             $(function () {
    23                 $("#box").mousedown(function (e) {
    24                     var disX = e.offsetX;
    25                     var disY = e.offsetY;
    26                     
    27                     $(document).mousemove(function (e) {
    28                         $("#box").css( {left: e.pageX-disX, top: e.pageY-disY} );
    29                     });
    30                     
    31                     $(document).mouseup(function () {
    32                         $(document).off("mousemove mouseup");
    33                     });
    34                 });
    35             
    36             })
    37         </script>
    38     </body>
    39 </html>

  • 相关阅读:
    Jquery入门
    微服务
    数组
    流程控制
    GO的整型
    Go的巧记
    变量和常量
    Golang
    股票入市指南
    linux 命令行操作
  • 原文地址:https://www.cnblogs.com/1032473245jing/p/7494611.html
Copyright © 2011-2022 走看看