13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ページ内の自動スクロール

13
Last updated at Posted at 2014-07-16
js
$(function () {
   $('a[href^=#]').click(function() {
        var speed = 400;
        var href= $(this).attr("href");
        var target = $(href == "#" || href == "" ? 'html' : href);
        var position = target.offset().top;
        $('body,html').animate({scrollTop:position}, speed, 'swing');
        return false;
   });
});
html
<a href="#move1">
   #move1に移動
</a>

<div id="move1">
   <p>ここに移動</p>
</div>

上記jsを記述しておくと、aタグをクリックした際、idで指定したリンク先に自動スクロールします。
ぬるぬる具合は、var speed = 400;の設定で変更可。

13
14
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
13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?