Skip to content

Commit ff0eb96

Browse files
Merge pull request #153 from maysam-gholampour/master
Add back-to-top button functionality and text justification
2 parents e190b72 + 067167e commit ff0eb96

File tree

7 files changed

+83
-14
lines changed

7 files changed

+83
-14
lines changed

_assets/scripts/js/back_to_top.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
document.addEventListener("DOMContentLoaded", function () {
2+
const btn = document.getElementById("backToTop");
3+
4+
window.onscroll = function () {
5+
const isVisible = btn.style.display === "block";
6+
7+
if (
8+
document.body.scrollTop > 300 ||
9+
document.documentElement.scrollTop > 300
10+
) {
11+
if (!isVisible) {
12+
btn.style.display = "block";
13+
btn.classList.add("pulse-once");
14+
setTimeout(() => btn.classList.remove("pulse-once"), 600);
15+
}
16+
} else {
17+
btn.style.display = "none";
18+
}
19+
};
20+
21+
btn.addEventListener("click", function () {
22+
window.scrollTo({ top: 0, behavior: "smooth" });
23+
});
24+
});

_css/adjust.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
font-size: var(--small);
55
}
66

7-
.franklin-content { font-size: 1.4rem; }
7+
.franklin-content { font-size: 1.4rem;
8+
text-align: justify;}
89

910
#main {
1011
float: left;

_css/franklin.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ html {
5959
FOOT / COPYRIGHT
6060
================================================================== */
6161

62-
.back-to-top {
63-
float: right;
64-
font-size: xx-large;
65-
padding-bottom: 3em;
66-
}
67-
68-
.back-to-top i {
69-
color: var(--color-purple)
70-
}
71-
7262
.franklin-content .page-foot a {
7363
text-decoration: none;
7464
}

_css/tufte.css

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,52 @@ label.margin-toggle:not(.sidenote-number) { display: none; }
439439
border-top-style: ridge;
440440
border-width: thin;
441441
}
442+
443+
444+
445+
446+
447+
448+
#backToTop {
449+
position: fixed;
450+
bottom: 20px;
451+
right: 20px;
452+
z-index: 999;
453+
display: none;
454+
width: 42px;
455+
height: 42px;
456+
border-radius: 50%;
457+
font-size: xx-large;
458+
border: none;
459+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
460+
transition: transform 0.2s ease, box-shadow 0.2s ease;
461+
}
462+
463+
#backToTop i {
464+
color: var(--color-purple)
465+
}
466+
467+
/* Hover effect: gently lift */
468+
#backToTop:hover {
469+
transform: translateY(-3px);
470+
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
471+
}
472+
473+
/* Gentle pulse when shown */
474+
#backToTop.pulse-once {
475+
animation: pulse-once 0.6s ease;
476+
}
477+
478+
@keyframes pulse-once {
479+
0% {
480+
transform: scale(0.8);
481+
opacity: 0.5;
482+
}
483+
60% {
484+
transform: scale(1.1);
485+
opacity: 1;
486+
}
487+
100% {
488+
transform: scale(1);
489+
}
490+
}

_layout/back_to_top.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- Back to top button -->
2+
<button id="backToTop" class="shadow" title="Back to top">
3+
<i class="fa fa-chevron-circle-up"></i>
4+
</button>
5+
6+
<script src="/assets/scripts/js/back_to_top.js"></script>

_layout/foot.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- CONTENT ENDS HERE -->
2+
{{insert back_to_top.html}}
23
</div> <!-- end of id=main -->
34
</div> <!-- end of id=layout -->
45
{{ if hasmath }}

_layout/page_foot.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<div class="back-to-top">
2-
<span><a href="#" title="Back to Top"><i class="fa fa-chevron-circle-up"></i></a></span>
3-
</div>
1+
42
{{ if weave }}
53
{{ else }}
64
<div class="page-foot">

0 commit comments

Comments
 (0)