تصف هذه المقالة استخدام المواقع المطلقة لـ JS لتحقيق تأثير العودة إلى الأعلى. شاركه للرجوع إليه ، على النحو التالي:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8"/> <title> تعود إلى الأزرار العلوية </title> type = "text/css"> body {margin: 0px ؛ padding: 0px ؛ الارتفاع: 2500px ؛ الخلفية:#6f0024 ؛}#div1 {width: 120px ؛ الارتفاع: 34px ؛ اليمين: 4px ؛ فينى: 5px ؛ corsor: pointer ؛ خلفية: url (Image/toTop) عدم التكرار ؛ الموضع: ثابت ؛ _position: absolute ؛ العرض: none ؛} </style> <script type = "text/javaScript"> // hide placement المطلقة دالة العرض getScroll (id) {var obj = document.getElementById (id) ؛ var timer = null ؛ الموضعية (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) ؛ وظيفة smove () {setScrollTop (getScrollTop () / 1.5) ؛ if (getScrollTop () <1) ClearInterval (timer) ؛ }}} ستر if (obj) {var top = obj.offsettop ؛ if (ie6) {document.documentElement.style.textoverflow = "Ellipsis" ؛ obj.style.position = "المطلق" ؛ OBJ.Style.setExpression ("Top" ، "eval (documentElement.ScrollTop +" + TOP + ') + "PX"') ؛ }) document.body.scrolltop ؛} // مرة أخرى إلى Top Function SetScrollTop (value) {document.documentElement.scrolltop = value ؛ document.body.scrolltop = value ؛} window.onload = function () {getScroll ('div1') ؛} ؛ </script> </head> <body> <div id = "div1"> </viv> </body> </html>لمزيد من المعلومات حول المحتوى المتعلق بـ javaScript ، يرجى مراجعة موضوعات هذا الموقع: "ملخص لتأثيرات وتقنيات تبديل JavaScript" ، "ملخص لمهارات خوارزمية بحث JavaScript" ، "ملخص لتأثيرات الرسوم المتحركة JavaScript و Techniques و" ملخص ". خوارزميات وتقنيات JavaScript Traversal "، و" ملخص استخدام العمليات الرياضية JavaScript "
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.