정

맨위로 가기 버튼

팁이랄건 없구요.

고수님들은 패스~~~

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

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

 

<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개

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

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

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

댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
22-12-16 조회 6,225
22-12-16 조회 7,882
22-12-14 조회 6,143
22-12-13 조회 6,319
22-12-09 조회 7,629
22-12-09 조회 7,109
22-12-07 조회 6,024
22-12-06 조회 8,061
22-12-03 조회 7,933
22-12-02 조회 7,121
22-11-30 조회 9,970
22-11-25 조회 6,787
22-11-22 조회 6,575
22-11-20 조회 6,280
22-11-16 조회 7,929
22-11-15 조회 6,200
22-11-15 조회 7,020
22-11-14 조회 6,142
22-11-10 조회 7,316
22-11-08 조회 6,894
22-10-28 조회 7,077
22-10-27 조회 7,793
22-10-26 조회 6,650
22-10-25 조회 7,495
22-10-22 조회 6,810
22-10-19 조회 7,286
22-10-18 조회 6,167
22-10-16 조회 6,761
22-10-16 조회 6,751
22-10-12 조회 7,912