zoukankan      html  css  js  c++  java
  • Jquery实现div拖拽

     Jquery实现div拖拽

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
    <html>  
    <head>  
      <title> New Document </title>  
      <script type="text/javascript" src="E:/jquery-1.7.2.min.js"></script>  
      <style type="text/css">  
    /*模块拖拽*/  
    .drag{position:absolute;width:100px;height:100px;border:1px solid #ddd;background:#FBF2BD;text-align:center;padding:5px;top:100px;left:20px;cursor:move;}  
    </style>  
      
    <script type="text/javascript">  
    // 模块拖拽  
    $(function(){  
    var _move=false;//移动标记  
    var _x,_y;//鼠标离控件左上角的相对位置  
        $(".drag").click(function(){  
            //alert("click");//点击(松开后触发)  
            }).mousedown(function(e){  
            _move=true;  
            _x=e.pageX-parseInt($(".drag").css("left"));  
            _y=e.pageY-parseInt($(".drag").css("top"));  
            $(".drag").fadeTo(20, 0.5);//点击后开始拖动并透明显示  
        });  
        $(document).mousemove(function(e){  
            if(_move){  
                var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置  
                var y=e.pageY-_y;  
                $(".drag").css({top:y,left:x});//控件新位置  
            }  
        }).mouseup(function(){  
        _move=false;  
        $(".drag").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明  
      });  
    });  
    </script>  
    </head>  
    <body>  
    <!--模块拖拽--> <div class="drag">这个可以拖动哦 ^_^</div>  
    </body>  
      
    </html>   

    $("#question_pic").bind("click",function(event){
             event.stopPropagation();  //防止冒泡事件响应
             $("#chat_question").hide("slow"); 

         });

    $("#chatLineHolder").scrollTop(10000);//保持最下一行,不用滚

  • 相关阅读:
    huffman(greedy)
    activity select problem(greedy algorithms)
    matrix_chain_order
    rod cutting
    the implemention of redblack tree
    oracle 数据库备份 cmd 命令
    jquery tab切换
    封装自己的js框架入门
    HTML5-Database Storage 本地存储.html
    exp导出oracle数据库时 无法导出空表的解决方法
  • 原文地址:https://www.cnblogs.com/juhualang/p/3883709.html
Copyright © 2011-2022 走看看