2
3

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.

JQuery - 画面内スムーズスクロール

Last updated at Posted at 2013-02-24
    /**
     * 画面内スムーズスクロールを行います。
     * @param scldurat 移動速度 大きくするとゆっくりになります。
     */
    $.fn.smoothScroller = function(option){
        $(this).click(function() {
            if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
                var target = $(this.hash);
                target = target.length && target;
                if (target.length) {
                    var sclpos = 30;
                    var targetOffset = target.offset().top - sclpos;
                    $('html,body')
                        .animate({scrollTop: targetOffset}, {duration: option.scldurat, easing: "easeOutExpo"});
                    return false;
                }
            }
        });
    };

使い方

    $('input[type=button]').smoothScroller({'scldurat':100});
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?