Skip to content

Commit

Permalink
ページトップボタンの自動処理修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kurudrive committed Jul 29, 2024
1 parent e1b51aa commit aa408b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assets/js/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions inc/pagetop-btn/js/pagetop-btn.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
var exist_id = document.body.id;
if(exist_id){
// use existing body ID
var body_id = exist_id.split(' ');
if (!body_id.find(item => item === 'top')){
document.getElementById('page_top').href = '#' + body_id[0];
if (exist_id !== 'top'){
document.getElementById('page_top').href = '#' + exist_id;
}
}
else{
} else{
// add #top on body
let new_id = 'top';
let newBodyId = 'top';

// check double ID
let i = 0;
const allElements = document.querySelectorAll('*');
while (Array.from(allElements).some(element => element.id === new_id)) {
new_id = `top`;
// 既存のHTML内に newBodyId の値と同じ id がある場合
while (Array.from(allElements).some(element => element.id === newBodyId)) {
newBodyId = `top`;
if( 0 < i ){
new_id += `-${i}`;
newBodyId += `-${i}`;
}
document.getElementById('page_top').href = '#' + new_id;
// page_top のリンク先を変更
document.getElementById('page_top').href = '#' + newBodyId;
i++;
}
}

document.body.id = new_id;
document.body.id = newBodyId;
}
})(window, document, 'ready');
2 changes: 1 addition & 1 deletion inc/smooth-scroll/js/smooth-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aa408b4

Please sign in to comment.