<!doctype Html>"Utf-8"><meta name="author"Content="Smart Club-zhinengshe.com"/><meta name="Copyright"Content="Smart Club-zhinengshe.com"/><title> Intelligent Society-Www.zhinengshe.com</title><style>*{margin:0;p adding:0; list-Style:none;} #div1 {position:absolute;left:0; Top:0; width:200px; height:200px; background:red;}</style><script>window.onload=function () {varOdiv = document.getElementById ("Div1"); varBleft = Btop = BRight = Bbottom =false; varStep =Ten; varBdarg =false; varJSON = {Width:oDiv.offsetWidth +"px", Height:"200px", left:0, Top:0, Background:"Red"}; function Initdiv (JSON) { for(varNameinchJSON) {Odiv.style[name]= Json[name];//?}} Document.onkeydown=function (EV) {varoevent = EV | |Event; varKeyCode =Oevent.keycode; Switch(keycode) { Case Panax Notoginseng: Bleft=true; Break; Case -: Btop=true; Break; Case the: BRight=true; Break; Case +: Bbottom=true; Break; } //CTRL + Q controls whether you can drag and drop if(Oevent.ctrlkey && KeyCode = =Bayi) {Bdarg= !Bdarg; if(Bdarg) {drag (); } Else{Nodrag (); } } //CTRL + Center point zoom in if(Oevent.ctrlkey && KeyCode = = -) {Btop=false; ODiv.style.width= Odiv.offsetwidth + step +"px"; ODiv.style.height= Odiv.offsetheight + step +"px"; ODiv.style.left= odiv.offsetleft-step/2+"px"; ODiv.style.top= odiv.offsettop-step/2+"px"; } //Ctrl + Lower center point zoom out if(Oevent.ctrlkey && KeyCode = = +) {Bbottom=false; ODiv.style.width= Odiv.offsetwidth-step +"px"; ODiv.style.height= Odiv.offsetheight-step +"px"; ODiv.style.left= Odiv.offsetleft + step/2+"px"; ODiv.style.top= Odiv.offsettop + step/2+"px"; } //Ctrl + ENTER restore to upper left corner if(Oevent.ctrlkey && KeyCode = = -){ //oDiv.style.cssText = "position:absolute;left:0;top:0;width:200px; height:200px; background:red; ";Initdiv (JSON); } }; Document.onkeyup=function (EV) {varoevent = EV | |Event; varKeyCode =Oevent.keycode; Switch(keycode) { Case Panax Notoginseng: Bleft=false; Break; Case -: Btop=false; Break; Case the: BRight=false; Break; Case +: Bbottom=false; Break; } }; SetInterval (function () {if(bleft) {ODiv.style.left= Odiv.offsetleft-step +"px"; } if(btop) {oDiv.style.top= Odiv.offsettop-step +"px"; } if(bRight) {ODiv.style.left= Odiv.offsetleft + step +"px"; } if(bbottom) {oDiv.style.top= Odiv.offsettop + step +"px"; } }, -); function Nodrag () {Odiv.onmousedown=NULL; } function drag () {Odiv.onmousedown=function (EV) {varoevent = EV | |Event; varDISX = Oevent.clientx-Odiv.offsetleft; varDisy = Oevent.clienty-Odiv.offsettop; Document.onmousemove=function (EV) {varoevent = EV | |Event; varl=oevent.clientx-Disx; vart=oevent.clienty-Disy; if(l<0) {L=0; }Else if(L > Document.documentElement.clientWidth-odiv.offsetwidth) {L= Document.documentElement.clientWidth-Odiv.offsetwidth; } if(t<0) {T=0; } Else if(T > Document.documentElement.clientHeight-odiv.offsetheight) {T= Document.documentElement.clientHeight-Odiv.offsetheight; } oDiv.style.left= L +"px"; ODiv.style.top= T +"px"; }; Document.onmouseup=function () {Document.onmousemove=NULL; Document.onmouseup=NULL; Odiv.releasecapture&& odiv.releasecapture ();//Release Capture }; //capture a bug that solves a drag-and-drop picture under IE, where the mouse is not moved directly to the target point when the picture is draggedOdiv.setcapture &&odiv.setcapture (); return false; }; } };</script>"Div1"></div></body>
Custom Div drag. Keyboard move up or down, ctrl+q control can be moved, CTRL + ENTER, return to the initial state