맨위로 가기 버튼

팁이랄건 없구요.

고수님들은 패스~~~

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

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

 

<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,458
3년 전 조회 2,096
3년 전 조회 3,490
3년 전 조회 1,832
3년 전 조회 1,549
3년 전 조회 2,629
3년 전 조회 2,347
3년 전 조회 1,465
3년 전 조회 3,339
3년 전 조회 3,508
3년 전 조회 2,641
3년 전 조회 5,188
3년 전 조회 2,476
3년 전 조회 2,256
3년 전 조회 2,042
3년 전 조회 3,391
3년 전 조회 1,989
3년 전 조회 2,743
3년 전 조회 1,825
3년 전 조회 2,884
3년 전 조회 2,610
3년 전 조회 2,553
3년 전 조회 3,389
3년 전 조회 2,266
3년 전 조회 3,070
3년 전 조회 2,457
3년 전 조회 2,901
3년 전 조회 1,856
3년 전 조회 2,303
3년 전 조회 2,358