There are many ways to Rome, of course I know that this can also be solved in other ways.
As you may have overlooked, the code was designed as a plugin. That's why the ready, scope!!
It's not about a CodeGolf competition.
In my opinion, your code is unnecessarily complicated, why use template?
Why the strange way via the hidden attribute, which is ultimately misused as a class?
Why assign the circle attribute in the CSS?
All of this means that the code shown does not work on IOS devices, for example!!
sample code, if you don't design it as a plugin:
.hidden { display: none; } .scroll-button { bottom: 10px; cursor: pointer; opacity: 0.5; position: fixed; right: 10px; transition: all ease 400ms; width: 50px; z-index: 1000; } .scroll-button:hover { opacity: 1; } .scroll-button circle { fill: red; } .scroll-button path { stroke: #fff; stroke-width: 15; stroke-linecap: round; }
document.body.insertAdjacentHTML( 'beforeend', `<svg xmlns:xlink="http://www.w3.org/1999/xlink" id = scrollButton class="scroll-button hidden" viewBox="0 0 100 100"> <circle cx="50" cy="50" r="50"></circle> <path d="M50 80 L50 20 M50 20 L80 50 M50 20 L20 50" /> </svg>` ) scrollButton.onclick=() => document.body.scrollIntoView( { behavior: "smooth" } ) window.addEventListener( 'scroll', () => scrollButton.classList.toggle('hidden', document.documentElement.scrollTop < 100 ))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There are many ways to Rome, of course I know that this can also be solved in other ways.
As you may have overlooked, the code was designed as a plugin. That's why the ready, scope!!
It's not about a CodeGolf competition.
In my opinion, your code is unnecessarily complicated, why use template?
Why the strange way via the hidden attribute, which is ultimately misused as a class?
Why assign the circle attribute in the CSS?
All of this means that the code shown does not work on IOS devices, for example!!
sample code, if you don't design it as a plugin:
css
Javascript: