jquery之窗口拖动




   $("#showTitle").mousedown(function (e) {
        vbool = true;
        vHeight = e.pageY;
        vWidth = e.pageX;
        cHeight = vHeight - $("#show").offset().top;
        cWdith = vWidth - $("#show").offset().left;
        //alert("divshow" + $("#show").offset().top + " divvHeight" + vHeight);
        //alert("高" + cHeight + " 宽" + cWdith);
    })
    $(document).mouseup(function () {
        vbool = false;
    })
    var showWidth = $("#show").width();
    var showHeight = $("#show").height();
    var documentWidth = $(document).width();
    var documentHeight = $(document).height();
    $(document).mousemove(function (e) {
        if (vbool) {
            var divheight = e.pageY - cHeight;//窗口要移动到的位置
            var divwidth = e.pageX - cWdith;//窗口要移动到的位置
            $("#la1").text(divheight + "w" + divwidth + "win" + showWidth + " x " + documentWidth + "" + showWidth);
            if (divwidth < 0) {
                divwidth = 0;
            }
            if (divheight < 50) {
                divheight = 50;
            }
            if (divwidth > documentWidth - showWidth) {
                divwidth = documentWidth - showWidth - 5;
            }
            if (divheight > documentHeight - showHeight) {
                divheight = documentHeight - showHeight - 5;
            }
            $("#show").css({ "left": divwidth, "top": divheight });
        }
    })




 

原文地址:https://www.cnblogs.com/cxd1008/p/6372443.html