JS를 사용하여이를 구현하기 위해 운영 요소 및 위치 요소를 사용하는 것이 좋습니다. 아래의 예가 있습니다. 필요한 친구들은 그것을 볼 수 있습니다.
<! docType html> <html> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"/> <title> 하루에 하나의 JavaScript 인스턴스 요소 포지셔닝 요소 </title> <tyle> div#a {width : 500px; } div {테두리 : 1px solid #000; 패딩 : 10px; } #cursor {위치 : 절대; 배경색 :#ff0; 너비 : 20px; 높이 : 20px; 왼쪽 : 50px; 상단 : 300px; } </style> <cript> 함수 positionObject (obj) {var rect = obj.getBoundingClientRect (); return [rect.left, rect.top]; } window.onload = function () {var tst = document.documentElement.getBoundingClientRect (); 경고 (tst.top); var cont = 'a'; var cursor = document.getElementById ( "커서"); while (cont) {cont = prompt ( "커서 블록을 어디에서 움직일 수 있습니까?", "a"); if (cont) {cont = cont.tolowercase (); if (cont == "a"|| cont == "b"|| cont == "c") {var elem = document.getElementById (cont); var pos = positionobject (elem); Console.log (POS); cursor.setattribute ( "style", "top :"+pos [1]+"px;"+"왼쪽 :"+pos [0]+"px"); }}}}}} </script> </head> <body> <div id = "a"> <p> a </p> <div id = "b"> <p> b </p> <div id = "c"> <p> c </p> </div> </div> <div id = "cursor"> </html> </html>