imported>=海豚= |
imported>=海豚= |
行 1: |
行 1: |
| // <pre>
| | 清除自動生成的刪除理由 <span style="font-size:smaller;"> 可用以保持刪除日誌 的 簡潔。此工具不影響列於URL 的 理由。</span> |
| /* 回到顶部 */
| |
| $(function() {
| |
| var body = document.body,
| |
| html = document.documentElement;
| |
| var innerWidth = window.innerWidth;
| |
| var scrollbarWidth;
| |
| switch ("scroll") {
| |
| case getComputedStyle(body).overflowY:
| |
| scrollbarWidth = innerWidth - body.clientWidth;
| |
| break;
| |
| case getComputedStyle(html).overflowY:
| |
| scrollbarWidth = innerWidth - html.clientWidth;
| |
| break;
| |
| default:
| |
| var backup = body.style.overflowY;
| |
| body.style.overflowY = "scroll";
| |
| scrollbarWidth = innerWidth - body.clientWidth;
| |
| body.style.overflowY = backup;
| |
| }
| |
| var btn = $("<div/>", {
| |
| "text": "返回顶部",
| |
| "attr": {
| |
| "title": "返回顶部",
| |
| "class": "backToTop"
| |
| },
| |
| "css": {
| |
| "user-select": "none"
| |
| },
| |
| "on": {
| |
| "click": function() {
| |
| $("html, body").animate({
| |
| scrollTop: 0
| |
| }, 120);
| |
| }
| |
| }
| |
| }).appendTo(document.body);
| |
| if (scrollbarWidth === 0) {
| |
| btn.css("right", "20px"); // 修复新版 Chrome 的 自动隐藏式滚动条导致 的 按钮被覆盖 chrome://flags/#overlay-scrollbars
| |
| }
| |
| $(window).on("scroll", function() {
| |
| $(document).scrollTop() > 0 ? btn.fadeIn() : btn.fadeOut();
| |
| }).scroll();
| |
| });
| |
| // </pre>
| |