この記事では、JSの絶対的な位置決めの使用がトップに戻る効果を達成することについて説明します。次のように、参照のために共有してください。
< xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <タイトルtype = "text/css"> body {margin:0px; padding:0px; height:height:2500px; background:#6f0024;}#div1 {width:120px; height:34px; right:4px; botton:5px; cursor:pointer:url(amigas/atop.png) NO-Repeat; position:sixt; _ position:absolute; display:none;} </stylive> <script = "text/javascript"> //絶対的な位置表示表示ディスプレイ機能getScroll(id){var obj = document.getElementbyid(id); varタイマー= null; PositionFixed(OBJ); if(obj){obj.style.display = 'none'; window.onscroll = function(){getScrolltop()> 0? obj.style.display = "block":obj.style.display = "none"; } obj.onclick = function(){var timer = setinterval(smove、10); function smove(){setscrolltop(getScrolltop() / 1.5); if(getScrolltop()<1)clearInterval(タイマー); }}}}} // Judge IE6関数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(documentlement.scrolltop +" + top + ') + "px"'); }}} // Scrollbar TopFunction getScrolltop()を取得{return document.documentelement.scrolltop ||を取得しますdocument.body.scrolltop;} //上部関数に戻るsetscrolltop(value){document.documentelement.scrolltop = value; document.body.scrolltop = value;} window.onload = function(){getScroll( 'div1');}; </script> </head> <body> <div id = "div1"> </div> </body> </html>JavaScript関連のコンテンツの詳細については、このサイトのトピックをご覧ください:「JavaScriptの切り替え効果とテクニックの要約」、「JavaScript検索アルゴリズムスキルの要約」、「JavaScriptアニメーション効果とテクニックの概要」、「Javascriptエラー、および「Javascriptデータ構造」の概要」の概要の要約の要約をご覧ください。 JavaScriptトラバーサルアルゴリズムとテクニック」、および「JavaScriptの数学的操作の使用法の要約」
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。