Skip to content

Commit

Permalink
floating buttonを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
howmuch515 committed Sep 9, 2024
1 parent f61c4ea commit e6fac8b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ nav {
.swiper {
width: 50vw;
height: 40vh;
}

#back-to-top {
display: none; /* ページ表示開始時はボタンは非表示 */
position: fixed;
bottom: 4vh;
right: 1vw;
z-index: 9999;
border-radius: 50%;
width: 3rem;
height: 3rem;
background-color: #555;
}
10 changes: 9 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,19 @@ <h1 id="お知らせ">お知らせ</h1>
<li><a href="#About">About</a></li>
<li><a href="#サービス紹介">サービス紹介</a></li>
<li><a href="#お知らせ">お知らせ</a></li>
<li><button data-tooltip="Top">Top</button></li>
</ul>
<ul>
<!-- dummy -->
</ul>
</nav>
</footer>

<a href="#" id="back-to-top">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="3rem" height="3rem" fill="white">
<path d="M12 4l-8 8h6v8h4v-8h6l-8-8z" />
</svg>
</a>

<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
<script src="./js/script.js"></script>
</body>
Expand Down
10 changes: 10 additions & 0 deletions docs/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ const swiper = new Swiper('.swiper', {
scrollbar: {
el: '.swiper-scrollbar',
},
});

const backToTopButton = document.getElementById('back-to-top');

window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
backToTopButton.style.display = 'block';
} else {
backToTopButton.style.display = 'none';
}
});

0 comments on commit e6fac8b

Please sign in to comment.