Skip to content

Commit 47d5fc2

Browse files
committed
Update go to top button
1 parent 7a694b3 commit 47d5fc2

File tree

4 files changed

+318
-315
lines changed

4 files changed

+318
-315
lines changed

static/css/main.css

+13-7
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,15 @@ body>footer a:hover {color: #eee}
345345
.tag_meta {color: #ccc;font-size: 12px;}
346346
.rsptime {padding: 0 .5em .5em .5em;background-image:none;border-bottom:none;font-size: .85em;color: #778899;background-color: var(--bar-bg-color);}
347347

348-
#go-to-top {
349-
display: none;
348+
a.top {
349+
font-size: 0;
350+
font-family: Helvetica,Arial,Verdana,sans-serif;
350351
position: fixed;
351-
right: 60px;
352352
bottom: 100px;
353+
font-weight: bold;
353354
padding: 10px;
354-
color: #666;
355-
background: #DDD;
356-
font: 24px/12px Helvetica,Arial,Verdana,sans-serif;
357-
opacity: 0.7;
355+
right: 1.618em;
356+
margin-bottom: 0;
358357
outline: 0 none;
359358
text-decoration: none;
360359
text-shadow: 0 0 1px #DDD;
@@ -363,7 +362,14 @@ body>footer a:hover {color: #eee}
363362
-khtml-border-radius: 5px;
364363
-webkit-border-radius: 5px;
365364
border-radius: 5px;
365+
transition: all .3s ease;
366+
text-align: center;
367+
color: #666;
368+
background: rgba(255, 255, 255, .5);
366369
}
370+
a.top.visible {font-size: 24px;}
371+
a.top:hover{background: rgba(200, 200, 200, .8);}
372+
367373
#id-msg {color: rgb(202, 60, 60);}
368374
#tag-cloud .tag_meta {font-style: italic}
369375

static/js/main.js

-7
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,4 @@ function postAjax(url, data, success) {
5050

5151
xhr.send(data);
5252
return xhr;
53-
}
54-
55-
function scrollToTop() {
56-
window.scrollTo({
57-
top: 0,
58-
behavior: "smooth"
59-
});
6053
}

views/ybs/base.qtpl

+14-12
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,21 @@ Page prints a page implementing Page interface.
6363
<footer role="contentinfo">
6464
{%= p.Footer() %}
6565
</footer>
66-
<a style="display: none; " rel="nofollow" href="#top" id="go-to-top">▲</a>
66+
<a rel="nofollow" href="#top" class="top" id="go-to-top">▲</a>
6767
<script>
68-
document.addEventListener("scroll", handleScroll);
69-
let scrollToTopBtn = document.getElementById("go-to-top");
70-
scrollToTopBtn.addEventListener("click", scrollToTop);
71-
72-
function handleScroll() {
73-
if (document.documentElement.scrollTop > 300) {
74-
scrollToTopBtn.style.display = "block";
75-
} else if (document.documentElement.scrollTop < 300){
76-
scrollToTopBtn.style.display = "none";
77-
}
78-
}
68+
(function (window, document) {
69+
let scrollToTopBtn = document.getElementById("go-to-top");
70+
document.addEventListener("scroll", function () {
71+
let top = window.scrollY || document.documentElement.scrollTop;
72+
scrollToTopBtn.classList.toggle('visible', top > 1000);
73+
});
74+
scrollToTopBtn.addEventListener("click", function () {
75+
window.scrollTo({
76+
top: 0,
77+
behavior: "smooth"
78+
});
79+
});
80+
})(this, this.document);
7981
</script>
8082
</body>
8183
</html>

0 commit comments

Comments
 (0)