LoginSignup
1
2

More than 5 years have passed since last update.

JavaScriptだけでTOPへ戻る

Last updated at Posted at 2015-10-31

こんなリンクつくって

<div id="toTop">
<a href="" onclick="scrollToTop(); return false">トップに戻る</a>
</div>

こうjs書いて

function scrollToTop() {
var y = document.body.scrollTop || document.documentElement.scrollTop;
if(y) {
scrollTo(0, y/=1.06);
setTimeout(scrollToTop, 1);
}
}

こうするとそれっぽい

#toTop {
position: fixed;
bottom: 18px;
right: 18px;
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2