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

Scroll top button #57

Open
wants to merge 4 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
57 changes: 30 additions & 27 deletions themes/coders-tokyo/layout/_partial/article.ejs
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<link
rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/dracula.min.css"
/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/dracula.min.css" />
<section>
<div class="container">
<article
id="<%= post.layout %>-<%= post.slug %>"
class="article article-type-<%= post.layout %>"
itemscope
itemprop="blogPost"
>
<article id="<%= post.layout %>-<%= post.slug %>" class="article article-type-<%= post.layout %>" itemscope
itemprop="blogPost">
<div class="article-inner row justify-content-center">
<div class="article-entry col-md-10 col-lg-8" itemprop="articleBody">
<% if (post.excerpt && index){ %> <%- post.excerpt %> <% if
(theme.excerpt_link){ %>
<p class="article-more-link">
<a href="<%- url_for(post.path) %>#more"
><%= theme.excerpt_link %></a
>
<a href="<%- url_for(post.path) %>#more"><%= theme.excerpt_link %></a>
</p>
<% } %> <% } else { %>
<div class="article__title">
Expand All @@ -31,35 +22,47 @@
<% } %> <% if (!index && post.comments && config.disqus_shortname){ %>
<section id="comments" class="pb-0">
<div id="disqus_thread">
<noscript
>Please enable JavaScript to view the
<a href="//disqus.com/?ref_noscript"
>comments powered by Disqus.</a
></noscript
>
<noscript>Please enable JavaScript to view the
<a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
<% } %> <% if (config.disqus_shortname){ %>
<script>
var disqus_shortname = '<%= config.disqus_shortname %>';
<% if (page.permalink){ %>
<% if (page.permalink) { %>
var disqus_url = '<%= page.permalink %>';
<% } %>
(function(){
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/<% if (page.comments) { %>embed.js<% } else { %>count.js<% } %>';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
(function () {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/<% if (page.comments) { %>embed.js<% } else { %>count.js<% } %>';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<% } %>
</div>
</div>
<button class="scroll_top_btn">
<img src="https://image.flaticon.com/icons/svg/120/120891.svg" alt="Scroll top icon">
</button>
</article>
</div>
</section>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
</script>
<!-- Scroll top button script -->
<script>
const button = document.querySelector('.scroll_top_btn');
const topScrollTo = function () {
if (window.scrollY > 0) {
setTimeout(function () {
window.scrollTo(0, window.scrollY - 40)
topScrollTo();
}, 2)
}
}
button.addEventListener('click', topScrollTo);
</script>
26 changes: 26 additions & 0 deletions themes/coders-tokyo/source/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ article .article__body h4 {
font-weight: 600;
}

article .scroll_top_btn {
position: fixed;
bottom: 1.3rem;
right: 7rem;
width: 54px;
height: 54px;
border-radius: 50%;
box-shadow: 5px 0 20px 5px rgba(0, 0, 0, 0.1);
border: none;
background: #fff;
transition: 200ms ease;
}
article .scroll_top_btn:active {
transform: scale(0.9);
}
article .scroll_top_btn img {
width: 28px;
height: auto;
}
@media (max-width: 768px) {
article .scroll_top_btn {
right: 6.2rem;
bottom: 0.68rem;
}
}

/* ------------------ Tuts Page ------------------ */
.course-thumbnail {
border-radius: 4px;
Expand Down