File tree Expand file tree Collapse file tree 3 files changed +21
-14
lines changed
Expand file tree Collapse file tree 3 files changed +21
-14
lines changed Original file line number Diff line number Diff line change 11{% assign t = site.data.locales[page.lang][page.lang] %}
2- < button id ="scrollToTopButton " title ="Go to top " aria-label ="Scroll to top ">
2+ < button id ="scrollToTopButton " type =" button " title ="Scroll to top " aria-label ="Scroll to top ">
33 < svg aria-hidden ="true " viewBox ="0 0 24 24 " focusable ="false ">
44 < path d ="M12 4L5 11h4v9h6v-9h4z "> </ path >
55 </ svg >
Original file line number Diff line number Diff line change 2626 width : 20px ;
2727 height : 26px ;
2828 display : block ;
29- fill : #6a737d ;
29+ fill : currentColor ;
3030}
Original file line number Diff line number Diff line change 11
2- window . addEventListener ( 'scroll' , function ( ) {
3- var scrollToTopButton = document . getElementById ( 'scrollToTopButton' ) ;
4- if ( window . scrollY > 300 ) {
5- scrollToTopButton . style . display = 'flex' ;
6- } else {
7- scrollToTopButton . style . display = 'none' ;
8- }
9- } ) ;
10-
11- document . getElementById ( 'scrollToTopButton' ) . addEventListener ( 'click' , function ( ) {
12- window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
13- } ) ;
2+ var scrollToTopButton = document . getElementById ( 'scrollToTopButton' ) ;
3+
4+ if ( scrollToTopButton ) {
5+ var toggleScrollToTopButton = function ( ) {
6+ if ( window . scrollY > 300 ) {
7+ scrollToTopButton . style . display = 'flex' ;
8+ } else {
9+ scrollToTopButton . style . display = 'none' ;
10+ }
11+ } ;
12+
13+ window . addEventListener ( 'scroll' , toggleScrollToTopButton ) ;
14+
15+ scrollToTopButton . addEventListener ( 'click' , function ( ) {
16+ window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
17+ } ) ;
18+
19+ toggleScrollToTopButton ( ) ;
20+ }
1421
You can’t perform that action at this time.
0 commit comments