0
0

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 3 years have passed since last update.

javascript スクロール機能をつけるとき

Last updated at Posted at 2020-07-12

#JavaScriptでスクロール機能をつけたいときのコードです
htmlタグの一番下に以下のコードを記入します。

<script>
$(function () {
      $('a[href^=#]').click(function () {
        var adjust = -50;
        var speed = 400;
        var href = $(this).attr("href");
        var target = $(href == "#" || href == "" ? 'html' : href);
        var position = target.offset().top + adjust;
        $('body,html').animate({scrollTop: position}, speed, 'swing');
        return false;
      });
    });
</script>

※adjustという変数は調整の意味です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?