Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created scrollTop feature #81

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions themes/coders-tokyo/layout/_partial/footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
</a>
</li>
<li>
<a href="https://www.youtube.com/watch?v=zIjRONNA_8Y&list=PLkY6Xj8Sg8-uPZnTdScfuH0xD-O6Kb-V-" target="_blank">
<a href="https://www.youtube.com/watch?v=zIjRONNA_8Y&list=PLkY6Xj8Sg8-uPZnTdScfuH0xD-O6Kb-V-"
target="_blank">
<i class="socicon socicon-youtube icon icon--xs"></i>
</a>
</li>
Expand All @@ -61,17 +62,35 @@
</div>
<!--end of row-->
</div>
<div id="scrollTop" class="scrollTop">
<img src="/images/up-arrow.svg" />
</div>
<!--end of container-->
</footer>

<%- js('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js') %>
<%- js('https://cdnjs.cloudflare.com/ajax/libs/flickity/2.1.1/flickity.pkgd.min.js') %>
<%- js('https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/14.2.1/smooth-scroll.min.js') %>
<%- js('js/scripts.js') %>
<script src="https://embed.small.chat/TAKF2JHMFGAY8GG7K5.js" async></script>

<script>
var scroll = new SmoothScroll('a[href*="#"]');
var scrollTopEl = document.querySelector("#scrollTop");
scrollTopEl.addEventListener("click", () => {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tranthaison1231 hiện tại mình đang dùng thư viện này để làm smooth scroll https://github.com/cferdinandi/smooth-scroll
Em học cách dùng rồi áp dụng

window.onscroll = onScroll;
function onScroll() {
if (
document.body.scrollTop > 30 ||
document.documentElement.scrollTop > 30
) {
scrollTopEl.classList.add("showScroll");
} else {
scrollTopEl.classList.remove("showScroll");
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

để performance tốt hơn thì nên sử dụng debounce hoặc throttle để giảm số lần hàm onScroll bị gọi

</script>

<!-- <footer id="footer">
Expand All @@ -84,4 +103,4 @@
<%= __('powered_by') %> <a href="http://hexo.io/" target="_blank">Hexo</a>
</div>
</div>
</footer> -->
</footer> -->
19 changes: 19 additions & 0 deletions themes/coders-tokyo/source/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ a {
/**! 02. Typography **/
html {
font-size: 87.5%;
scroll-behavior: smooth;
}
@media all and (max-width: 768px) {
html {
Expand Down Expand Up @@ -9342,3 +9343,21 @@ footer.footer-7 {
margin-right: auto;
}
}
.scrollTop {
position: fixed;
bottom: 0;
width: 40px;
right: 0;
margin: 1.5rem;
transform: translateY(200%);
transition: all 600ms ease-in;
opacity: 0;
cursor: pointer;
}
.scrollTop img {
width: 100%;
}
.showScroll {
transform: translateY(0);
opacity: 1;
}
43 changes: 43 additions & 0 deletions themes/coders-tokyo/source/images/up-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.