Help us understand the problem. What is going on with this article?

jqueryでページトップを使用する(例)

More than 1 year has passed since last update.

ページトップのJSを使用する場合(例)

定義側js↓

pageTop.js
$(window).load(function(){
  function pageTop () {

    var $main         = $('html, body');
    var $pTop         = $('.pagetop');
    var $header       = $('header');
    var $scrollPos    = '';
    var $headerHeight = $header.outerHeight();
    var $headerOfset  = $headerHeight + $header.offset().top;


    //ページトップボタン非表示
    $pTop.hide();

    $(window).on('scroll', function() {

        $scrollPos = $(this).scrollTop();

        if ($headerOfset < $scrollPos) {
            $pTop.fadeIn();
        } else {
            $pTop.fadeOut();
        }

    });

    $pTop.on('click', function() {

        $main.animate({
            scrollTop:$main.offset().top
        }, 2000, "easeOutQuint");

        return false;

    });

  }
});

呼び出し側js↓

common.js
$(window).load(function(){
  pageTop();
});

定義側html↓

index.html
<script src="./js/jquery-1.11.0.min.js"></script>
<script src="./js/jquery.easing.1.3.js"></script>
<script src="./js/pageTop.js"></script>

jquery.easing.1.3.jsは別に読まなくてもページトップのjsを使用できるが、easingを使用する際は必須。
もし、必要ないなら、「easeOutQuint」を消す。

ryuji62
28歳プログラマです。 以下経験↓ ・HTML、CSSを用いたコーディング ・JS(Jquery)、CSS3を用いた動き ・PHP、SQLを用いたデータベースの構築とオリジナルCMSの作成 ・JAVAを用いたAndroidアプリ制作(実践はないが、特に勉強中) ・gulpを用いてejsを用いてのコーディング環境構築
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした