The following code is placed in a adapt.js file (function (Doc, win) { var docEl = doc.documentelement, resizeevt = ' Orientationchange ' in window ? ' orientationchange ' : ' resize ', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientwidth) return; docel.style.fontsize = 20 * (clientwidth /750) + ' px '; }; if (!doc.addeventlistener) return; win.addeventlistener ( Resizeevt, recalc, false); doc.addeventlistener (' domcontentloaded ', recalc, false);}) (Document, window); Function gotopex () { var obj = document.getelementbyid (" Gotopbtn "); function getscrolltop () &nBsp { return document.documentelement.scrolltop + document.body.scrolltop; } Function setscrolltop (value) { if (DOCUMENT.DOCUMENTELEMENT.SCROLLTOP) { Document.documentelement.scrolltop = value; } else { document.body.scrolltop = value; } } window.onscroll = function () { getScrollTop () > 0 ? obj.style.display = "": obj.style.display = "none"; } obj.onclick = function () { var gotop = setinterval (scrollMove, function scrollmove () { setscrolltop (Getscrolltop () / 1.1); if ( Getscrolltop () < 1) clearinterval (gotop); } } }
HTML Document code:
<script src= "Js/adapt.js" ></script><--the following is more than the height shown back to the top of the code--><div id= "gotopbtn" ></div> <script Type=text/javascript>gotopex ();</script>
Ultra-Easy mobile End layout adaptive size rem Judging js file and exceeding a certain height back to top button code