Betriebselemente und Positionierungselemente, die JS zum Implementieren verwenden, ist eine gute Wahl. Nachfolgend finden Sie ein Beispiel. Freunde, die es brauchen, können es sich ansehen.
<! DocType html> <html> <kopf> <meta http-äquiv = "content-type" content = "text/html; charset = utf-8"/> <title> Eine Javascript-Instanz pro Tag operieren Element </title> <Stil> div#a {widTth: 500px; } div {border: 1px fest #000; Polsterung: 10px; } #Cursor {Position: absolut; Hintergrundfarbe:#ff0; Breite: 20px; Höhe: 20px; links: 50px; Oben: 300px; } </style> <script> Funktion PositionObject (obj) {var rect = obj.getBoundingClientRect (); return [rect.left, rect.top]; } window.onload = function () {var tst = document.documentElement.getBoundingClientRect (); Alert (tst.top); var cont = 'a'; var cursor = document.getElementById ("Cursor"); while (cont) {cont = prompt ("Wo möchten Sie den Cursorblock verschieben?", "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;"+"links:"+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> <div id="cursor"> </div> </body> </html>