Este artigo descreve o uso do posicionamento absoluto de JS para alcançar o efeito de voltar ao topo. Compartilhe -o para sua referência, como segue:
<! xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> posicionamento absoluto de volta para topo. type = "text/css"> corpo {margem: 0px; preenchimento: 0px; altura: 2500px; fundo:#6f0024;}#div1 {width: 120px; altura: 34px; direita: 4px; inferior: 5px; cursor: ponteiro; background: url (imagens/toTOP.P.P; sem repetição; posição: fixo; _Position: Absolute; Display: Nenhum;} </style> <script type = "text/javascript"> // Posicionamento absoluto Hide Exibir Função getSCroll (id) {var obj = document.getElementById (id); Var Timer = NULL; POISSOFIXED (OBJ); if (obj) {obj.style.display = 'nenhum'; window.onscroll = function () {getSCrolltop ()> 0? obj.style.display = "bloco": obj.style.display = "nenhum"; } obj.OnClick = function () {var timer = setInterval (Smove, 10); function Smove () {SetScrolltop (getSCrolltop () / 1.5); if (getsCrolltop () <1) clearInterval (timer); }}}}} // JULGE IE6 FUNÇÃO POSITIONFIXED (OBJ) {var ie6 =!-[1,] &&! Window.xmlhttprequest; if (obj) {var top = obj.offSettop; if (ie6) {document.documentElement.style.textoverflow = "elipsis"; obj.style.Position = "Absolute"; obj.style.setexpression ("top", "avaliar (documentElement.scrolltop +" + top + ') + "px"'); }}} // Obtenha a função superior de scrollBar getScrolltop () {return document.documentElement.scrolltop || Document.Body.Scrolltop;} // Voltar para a função Top SetScrolltop (value) {document.documentElement.scrolltop = value; document.body.scrolltop = value;} window.onload = function () {getsCroll ('div1');}; </script> </ad 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 e Técnicas de Traversal "e" Resumo do Uso do Javascript Mathematic Operations "
Espero que este artigo seja útil para a programação JavaScript de todos.