Este artigo compartilhou o efeito do JavaScript de volta ao topo para sua referência. O conteúdo específico é o seguinte
<! Doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <meta http-equiv = "x-ua compatível com" content = "ie = borda, chrome = 1"> <title> para o efeito superior js) </title> <styne type =; } .bg {width: 1022px; margem: 0 automático; } .btn {display: Nenhum; Largura: 75px; Altura: 75px; Antecedentes: URL (../ Images/Web Top Pequeno Ícone (retorne a cima)/retorne ao top-085.png) Nopating, no topo da esquerda; Posição: fixado; Esquerda: 50%; margem-esquerda: 530px; Inferior: 10px; Indente de texto: -9999px; Esboço: Nenhum; } .btn: hover {posição de fundo: 0 -75px; } </style> <cript> var timer = null; var isscroll = true; //1.2 Construa a função Oscroll função Oscroll () {var ostop = document.documentElement.Scrolltop || document.body.scrolltop; // 1.1 altura de rolagem, compatível com var oSPEED = math.ceil (ostop/4);//////scroll document.TocumentMement.ScrolltoPOPOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOLTOT.SCROLLOTPOT.SCROLLTOLPOT.SCROLLTOLPOT.SCROLLTOLTOMENT.SCROLLTOLTOLT.SCROLLOT. if (ostop == 0) {// julgar o alcance da parte superior, limpe o timer clearInterval (timer); } ISSCROLL = true; } window.onload = function () {var obtn = document.getElementById ('btn'); // obtenha o elemento do botão var clientHeight = document.documentElement.clientHeight || document.body.clientHeight; // 1. Clique no evento de retorno BTN.OnCLICK = function () {// Ligue o botão Clique em Timer = setInterval (Oscroll, 50); } window.onscroll = function () {var ostop = document.documentElement.Scrolltop || document.body.scrolltop; // 1.1 altura de rolagem, compatível if (ostop> clientHeight) {btn.style.display = "bloco"; } else {btn.style.display = "nenhum"; } if (! issCroll) {clearInterval (timer); } ISSCROLL = false; }} </sCript> </head> <body> <div> <img src = "../ imagens/jz.jpg"> </div> <a href = "javascript: void (0);" id = "btn"> de volta ao topo </a> </body> </html>O exposto acima é tudo sobre este artigo, e espero que seja útil que todos aprendam programação de JavaScript.