div Layer Drag:
Realize:
Css:
View Code
<style>div {position:relative;} </style>
Js:
View Code
<script type= "Text/javascript" >varMouseover=truevarXcoor;varYcoor;functioncoordinates () {if(Event.srcElement.id.indexOf ("wishbroad") = = 0) {Event.srcElement.style.zIndex= 1000; MouseOver=true; Pleft=Event.srcElement.style.pixelLeft; Ptop=Event.srcElement.style.pixelTop; Xcoor=Event.clientx; Ycoor=Event.clienty; Document.onmousemove=Moveimage; }}functionMoveimage () {if(mouseover&&event.button==1) {Event.srcElement.style.pixelLeft=pleft+event.clientx-Xcoor; Event.srcElement.style.pixelTop=ptop+event.clienty-Ycoor; return false; }}functionMouseUp () {Event.srcElement.style.zIndex= 1; MouseOver=false;} Document.onmousedown=Coordinates;document.onmouseup=MouseUp;</script>
Html:
View Code
<HTML><Head>div Layer Drag</Head><Body><DivID= "Wishbroad1"style= "width:200px; height:100px;border:1px solid black;background:gray;">China</Div><DivID= "Wishbroad2"style= "width:200px; height:100px;border:1px solid red;background:red;">United States</Div><DivID= "Wishbroad3"style= "width:200px; height:100px;border:1px solid red;background:green;">Japan</Div><DivID= "Wishbroad4"style= "width:200px; height:100px;border:1px solid red;background:pink;">Brazil</Div></Body></HTML>
Note: for reference only. Not considering compatibility, IE9 test pass! Google is not moving! Other self-test.
CSS: CSS drop-down menu effect without JS implementation JavaScript: Nine Kinds of JS popup dialog box Common JavaScript JavaScript: Exporting a table to Excel jquery table interlaced background and highlighting when moving forward jquery randomly generates dynamic vertical bar voting results jquery China provinces and cities no refresh three level linkage query |
Javascript:div Layer Drag Effect