jquery 實現鼠標點擊div盒子移動功能


// Start 窗口的拖動  
         var _move=false;                 //移動標記   
         var _x,_y;                            //鼠標離控件左上角的相對位置   
        $(document).ready(function(){
                $(".box h4").click(function(){  
//                    alert("click");//點擊(松開后觸發)
                }).mousedown(function(e){
                    var _this = $(".box");
                    if(!_move){  
                        _move=true;   
                        _x=e.pageX-parseInt(_this.css("left"));   
                        _y=e.pageY-parseInt(_this.css("top")); 
                    }else{  
                        _move=false; 
                    }                          
                 });   
                 $(document).mousemove(function(e){   
                        var _this = $(".box");
                        if(_move){   
                            var x=e.pageX-_x;                                   
                            var y=e.pageY-_y;   
                            _this.css({top:y,left:x});                 
                         }   
                  }).mouseup(function(){   
                      var _this = $(".box");
                           _move=false;   
                  }); 
        });  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM