原文:https://blog.csdn.net/insgo/article/details/113799700
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
(function() { 'use strict'; var toTopBtn = document.createElement('button') toTopBtn.innerHTML = "返回顶部"toTopBtn.className = "a-b-c-d-toTop"toTopBtn.onclick = function(e) { scrollTo(0, 0) } var body = document.body var style = document.createElement('style') style.id = "a-b-c-d-style" var css = `.a - b - c - d - toTop { position: fixed; bottom: 10 % ; right: 5 % ; width: 50px; height: 50px; border - radius: 50 % ; font - size: 15px; z - index: 999; cursor: pointer; font - size: 12px; overflow: hidden; }` if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } body.appendChild(toTopBtn) body.appendChild(style) })();
|