PageSourceSearch

https://boukenkan.com/wp-content/themes/boukenkan/common/js/jquery.smoothscroll.js

js boukenkan.com collected 2026-09-24 10:02:15 UTC 4,706 bytes, 133 lines download raw bytes

1//ページトップ
2$(function() {
3    var pagetop = $('#page-top');
4    var snsBtn = $('.sns-btn');
5    // ボタン非表示
6    pagetop.hide();
7    snsBtn.hide();
8
9    // 100px スクロールしたらボタン表示
10    $(window).scroll(function() {
11        if ($(this).scrollTop() > 100) {
12            pagetop.fadeIn();
13            snsBtn.fadeIn();
14        } else {
15            pagetop.fadeOut();
16            snsBtn.fadeOut();
17        }
18    });
19    pagetop.click(function() {
20        $('body, html').animate({
21            scrollTop: 0
22        }, 500);
23        return false;
24    });
25});
26
27//アンカースクロール
28var $win = $(window);
29$win.on('load resize', function() {
30    var windowWidth = window.innerWidth;
31
32    if (windowWidth > 1000) {
33        // PCの処理
34        $(function() {
35
36            //#で始まるアンカーをクリックした場合に処理
37            $('a[href^="#"]').click(function() {
38                // スクロールの速度
39                var speed = 500; // ミリ秒
40                // アンカーの値取得
41                var href = $(this).attr("href");
42                // 移動先を取得
43                var target = $(href == "#" || href == "" ? 'html' : href);
44                // 移動先を数値で取得
45                //ヘッダーの高さ
46                var hedderHeight = 90;
47                var position = target.offset().top - hedderHeight;
48                // スムーススクロール
49                $('body,html').animate({
50                    scrollTop: position
51                }, speed, 'swing');
52                return false;
53            });
54        });
55        // 別ページからのリンク
56        $(window).on('load', function() {
57            var headerHight = 90; //ヘッダの高さ
58            if (document.URL.match("#")) {
59                var str = location.href;
60                var cut_str = "#";
61                var index = str.indexOf(cut_str);
62                var href = str.slice(index);
63                var target = href;
64                var position = $(target).offset().top - headerHight;
65                $("html, body").scrollTop(position);
66                return false;
67            }
68
69        });
70    } else {
71        // SPの処理
72        $(function() {
73
74            //#で始まるアンカーをクリックした場合に処理
75            $('a[href^="#"]').click(function() {
76                // スクロールの速度
77                var speed = 500; // ミリ秒
78                // アンカーの値取得
79                var href = $(this).attr("href");
80                // 移動先を取得
81                var target = $(href == "#" || href == "" ? 'html' : href);
82                // 移動先を数値で取得
83                //ヘッダーの高さ
84                var hedderHeight = 60;
85                var position = target.offset().top - hedderHeight;
86                // スムーススクロール
87                $('body,html').animate({
88                    scrollTop: position
89                }, speed, 'swing');
90                return false;
91            });
92        });
93        // 別ページからのリンク
94        $(window).on('load', function() {
95            var headerHight = 60; //ヘッダの高さ
96            if (document.URL.match("#")) {
97                var str = location.href;
98                var cut_str = "#";
99                var index = str.indexOf(cut_str);
100                var href = str.slice(index);
101                var target = href;
102                var position = $(target).offset().top - headerHight;
103                $("html, body").scrollTop(position);
104                return false;
105            }
106
107        });
108    }
109});
110
111// Firefox位置ずれ修正
112window.onpageshow = function() {
113    //ページのURLからアンカー部分を取得
114    var myhash = $(location).attr('hash');
115    if (myhash.length > 1) { //アンカーがあった場合
116        if ($(myhash).length) { //アンカーに対応するidの要素があった場合
117            var nScrolltop = $(window).scrollTop();
118            var nOffset = $(myhash).offset().top;
119            //現在のスクロール位置とアンカーに対å¿
119œã™ã‚‹idのY座標(本来有るべき位置)を取得
120            if (Math.abs(nScrolltop - nOffset) > 5) { //2つの位置の差が5以下の場合
121                //本来有るべき位置に調整
122                $(window).scrollTop(nOffset);
123                console.log("調整しました");
124            } else {
125                console.log("調整の必要なし");
126            }
127        } else {
128            console.log("idに対応する要素がない");
129        }
130    } else {
131        console.log("アンカーがない");
132    }
133};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.