Este artículo describe el uso del posicionamiento absoluto de JS para lograr el efecto de Back a la parte superior. Compártelo para su referencia, como sigue:
< xmlns = "http://www.w3.org/1999/xhtml"> <fead> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> posicionamiento absoluto hacia atrás </title> <estilo type = "text/css"> cuerpo {margen: 0px; relleno: 0px; altura: 2500px; fondo:#6f0024;}#div1 {ancho: 120px; altura: 34px; derecha: 4px; fondo: 5px; cursor: pointer; fondo: url (imágenes/totop.png) No-Repeat; posición: fijo; _position: Absolute; Display: Ninguno;} </style> <script type = "text/javaScript"> // posicionamiento absoluto ocultar la función de visualización getScroll (id) {var obj = document.getElementById (id); VAR TIMER = NULL; positionfixed (obj); if (obj) {obj.style.display = 'none'; window.onscroll = function () {getscrolltop ()> 0? obj.style.display = "bloque": obj.style.display = "none"; } obj.onClick = function () {var timer = setInterval (smove, 10); function smove () {setScrollTop (getscrolltop () / 1.5); if (getsCrollTop () <1) ClearInterval (temporizador); }}}}} // juzga IE6 Función Positionfixed (obj) {var ie6 =!-[1,] &&! Window.xmlhttprequest; if (obj) {var top = obj.offsettop; if (ie6) {document.documentelement.style.textoverflow = "ellipsis"; obj.style.position = "Absolute"; obj.style.setExpression ("top", "eval (documentElement.scrolltop +" + top + ') + "px"'); }}} // Obtenga la función superior de Scrollbar getScrollTop () {return document.documentelement.scrolltop || document.body.scrolltop;} // retroceder a la función superior setscrolltop (valor) {document.documentelement.scrolltop = valor; document.body.scrolltop = value;} window.onload = function () {getscroll ('div1');}; </script> </head> <body> <div id = "div1"> </div> </body> </html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript Algoritmos y técnicas de recorrido ", y" Resumen del uso de operaciones matemáticas de JavaScript "
Espero que este artículo sea útil para la programación de JavaScript de todos.