欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)鼠標(biāo)拖動div改變位置、大小的實踐

 更新時間:2021年04月09日 14:42:40   作者:As_zyh  
這篇文章主要介紹了jQuery實現(xiàn)鼠標(biāo)拖動div改變位置、大小的實踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

       實現(xiàn)類似windows窗體的效果,在中間拖動改變div位置,在邊緣拖動改變div大小,鼠標(biāo)在相應(yīng)的位置改變成相應(yīng)的形狀
效果如圖: (截圖沒顯示鼠標(biāo))

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

代碼如下:

			$(".test1").mousemove(function(e){
                $(".test1").unbind("mousedown");
                $(".test1").css("cursor","default");
                //$("span > b").text(parseInt($("div").width()));
                var left = $(".test1").offset().left;
                var top = $(".test1").offset().top;

                // 如果鼠標(biāo)在中間
                if(e.clientX - left > 10 && e.clientX-left < parseInt($(".test1").width()) - 10 
                && e.clientY - top  > 10 && e.clientY-top  < parseInt($(".test1").height()) - 10) {
                    $(".test1").css("cursor","move");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var y = e.pageY - $(".test1").offset().top;
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"left":e.pageX - x, "top":e.pageY - y});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }
                
                //如果鼠標(biāo)在左上角
                if(e.clientX - left < 10 && e.clientY - top < 10) {
                    $(".test1").css("cursor","nw-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY + parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":h - e.pageY, "top":e.pageY - y});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX + parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":w - e.pageX, "left":e.pageX - x});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在上
                if(e.clientY - top < 10 && e.clientX - left > 10 && e.clientX-left < parseInt($(".test1").width()) - 10) {
                    $(".test1").css("cursor","n-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY + parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":h - e.pageY, "top":e.pageY - y});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在右上角
                if(e.clientY - top < 10 && e.clientX-left > parseInt($(".test1").width()) - 10) {
                    $(".test1").css("cursor","ne-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY + parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":h - e.pageY, "top":e.pageY - y});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX - parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":e.pageX - w});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在右
                if(e.clientX-left > parseInt($(".test1").width()) - 10 && e.clientY - top > 10 && e.clientY-top  < parseInt($(".test1").height()) - 10) {
                    $(".test1").css("cursor","e-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX - parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":e.pageX - w});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在右下
                if(e.clientX-left > parseInt($(".test1").width()) - 10 && e.clientY-top  > parseInt($(".test1").height()) - 10) {
                    $(".test1").css("cursor","se-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX - parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":e.pageX - w});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY - parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":e.pageY - h});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在下
                if(e.clientY-top  > parseInt($(".test1").height()) - 10 && e.clientX - left > 10 && e.clientX-left < parseInt($(".test1").width()) - 10) {
                    $(".test1").css("cursor","s-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY - parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":e.pageY - h});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }

                //如果鼠標(biāo)在左下
                if(e.clientY-top  > parseInt($(".test1").height()) - 10 && e.clientX - left < 10) {
                    $(".test1").css("cursor","sw-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX + parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":w - e.pageX, "left":e.pageX - x});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var y = e.pageY - $(".test1").offset().top;
                        var h = e.pageY - parseInt($(".test1").css("height"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"height":e.pageY - h});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }
                
                //如果鼠標(biāo)在左
                if(e.clientX - left < 10 && e.clientY - top > 10 && e.clientY-top < parseInt($(".test1").height()) - 10) {
                    $(".test1").css("cursor","w-resize");
                    $(".test1").mousedown(function(e) {
                        var ismove = true;
                        var x = e.pageX - $(".test1").offset().left;
                        var w = e.pageX + parseInt($(".test1").css("width"));
                        $(document).mousemove(function(e) {
                            if(ismove) {
                                $(".test1").css({"width":w - e.pageX, "left":e.pageX - x});
                            }
                        }).mouseup(function() {
                            ismove = false;
                        });
                    });
                }
            });

到此這篇關(guān)于jQuery實現(xiàn)鼠標(biāo)拖動div改變位置、大小的實踐的文章就介紹到這了,更多相關(guān)jQuery 鼠標(biāo)拖動div內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論