LoginSignup
0
0

More than 5 years have passed since last update.

javascript関連備忘録

Posted at

js関連の備忘録。随時追記。

ページ内リンクの移動アクション

jquery使用時

hoge.html
<a href="#bottom">下へスムース!</a>

<div id="bottom">
ここまで移動
</div>

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

参考:【jQuery】ページ内リンクをするするーっとスムースにスクロールするJavascript | KLUTCHE

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