맨위로 가기 버튼

팁이랄건 없구요.

고수님들은 패스~~~

그냥 필요에 의해서 구글링 해서 맞게 수정해봤습니다.

일단, 저희 사이트에선 잘 구동해서 맨날 얻어만 가는 보답을 좀 해 봅니다.

 

<style>

#myBtn {

  display: none;

  position: fixed;

  bottom: 20px;

  right: 30px;

  z-index: 99;

  font-size: 18px;

  border: none;

  outline: none;

  background-color: red;

  color: white;

  cursor: pointer;

  padding: 15px;

  border-radius: 4px;

}

 

#myBtn:hover {

  background-color: #555;

}

</style>

 

<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>

 

<script>

// Get the button

let mybutton = document.getElementById("myBtn");

 

// When the user scrolls down 20px from the top of the document, show the button

window.onscroll = function() {scrollFunction()};

 

function scrollFunction() {

  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {

    mybutton.style.display = "block";

  } else {

    mybutton.style.display = "none";

  }

}

 

// When the user clicks on the button, scroll to the top of the document

function topFunction() {

  document.body.scrollTop = 0;

  document.documentElement.scrollTop = 0;

}

</script>

 

|

댓글 6개

감사합니다
좋네요 감사합니다~
감사합니다 좋습니다~

감사합니다 덕북에 해결했어요~ 

감사합니다. 유용하게 잘 쓰겠습니다.

댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
3년 전 조회 3,335
3년 전 조회 2,013
3년 전 조회 3,392
3년 전 조회 1,754
3년 전 조회 1,477
3년 전 조회 2,533
3년 전 조회 2,259
3년 전 조회 1,381
3년 전 조회 3,250
3년 전 조회 3,415
3년 전 조회 2,556
3년 전 조회 5,031
3년 전 조회 2,400
3년 전 조회 2,166
3년 전 조회 1,962
3년 전 조회 3,296
3년 전 조회 1,927
3년 전 조회 2,638
3년 전 조회 1,747
3년 전 조회 2,803
3년 전 조회 2,545
3년 전 조회 2,476
3년 전 조회 3,301
3년 전 조회 2,197
3년 전 조회 2,990
3년 전 조회 2,388
3년 전 조회 2,822
3년 전 조회 1,798
3년 전 조회 2,216
3년 전 조회 2,286
🐛 버그신고