Skip to content

Commit 142929c

Browse files
committed
Add back to top button on en page
1 parent 0dfa03b commit 142929c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tutorial.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,29 @@ div.tright, div.floatright, table.floatright {
128128
border: medium none !important;
129129
direction: ltr;
130130
}
131+
132+
.backtop-box {
133+
position: fixed; left: 180px; bottom: 20px;
134+
}
135+
.backtop-box b {
136+
display: block; cursor: pointer;
137+
width: 40px; height: 40px;
138+
opacity: 0;
139+
background: #fff;;
140+
text-align: center;
141+
border: 1px solid #aaa;
142+
border-radius: 18px 2px 2px 2px;
143+
-moz-border-radius: 18px 2px 2px 2px;
144+
-webkit-border-radius: 18px 2px 2px 2px;
145+
-o-border-radius: 18px 2px 2px 2px;
146+
-ms-border-radius: 18px 2px 2px 2px;
147+
line-height: 40px;
148+
color: #666;
149+
}
150+
.backtop-box b:hover {
151+
background: #eee;
152+
}
153+
.backtop-box-show b {
154+
opacity: 1;
155+
}
156+

utils/gen-html-index-en.pl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,41 @@
101101

102102
$res .= "</section>\n";
103103

104+
$res .= <<_EOC_;
105+
<script>
106+
function init_back_top() {
107+
function _fn() {
108+
var t = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
109+
if (t > 5) {
110+
if (! show) {
111+
show = true;
112+
r.className = 'backtop-box-show';
113+
}
114+
} else {
115+
if (show) {
116+
show = false;
117+
r.className = '';
118+
}
119+
}
120+
}
121+
122+
var r = document.createElement('div');
123+
document.body.appendChild(r);
124+
r.innerHTML = '<div class="backtop-box"><b title="Jump to Top of Page">Top</b></div>';
125+
126+
var show = false;
127+
r.onclick = function() {
128+
window.scrollTo(0, 0);
129+
};
130+
131+
window.onscroll = _fn;
132+
window.onresize = _fn;
133+
}
134+
135+
init_back_top();
136+
</script>
137+
_EOC_
138+
104139
$res .= "</body></html>";
105140

106141
if ($outfile) {

0 commit comments

Comments
 (0)