The JavaScript layout transformation is to set the original floating layout through the JavaScript properties Offsetleft and offsettop default values in JS to give the element absolute positioning.
Original: Disadvantage-we want to add a drag-and-drop event to the image on the page we found that no location is impossible to complete all we have to use the following layout conversion
1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<style>5* {margin:0; padding:0;}6 7 #ul1 {width:660px; position:relative; margin:10px Auto;}8#ul1 li {width:200px; height:150px;float: Left; list-style:none; margin:10px;}9</style>Ten<script> One</script> A<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> -<title> Untitled Document </title> - the -<body> -<ul id= "UL1" > -<li></li> +<li></li> -<li></li> +<li></li> A<li></li> at<li></li> -<li></li> -<li></li> -<li></li> -<li></li> -</ul> in</body> -After conversion: After the conversion through JS to each Li gave absolute positioning
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">;} #ul1 {width:660px; position:relative; margin:10px Auto;} #ul1 li {width:200px; height:150px;float: Left; list-style:none; margin:10px;}</style><script>window.onload=function(){ varUl1=document.getelementbyid (' Ul1 '); varLis=ul1.getelementsbytagname (' Li '); varapos=[]; //get the Keft and top of each Li element saved to apos with a for loop for(i=0;i<lis.length;i++) {Apos[i]={Left:lis[i].offsetleft,top:lis[i].offsettop}}//To add the last saved value to an element through a for loop for(i=0;i<lis.length;i++) {Lis[i].style.left=apos[i].left+ ' px '; Lis[i].style.top=apos[i].top+ ' px '; Lis[i].style.position= ' absolute '; Lis[i].style.margin= ' 0 '; }}</script><meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> Untitled document </title>JavaScript Layout transformation