JQuery

 

css

<style>
/* Scroll to top
---------------------------------- */
.scrollToTop {
  color: #ffffff;
  position: fixed;
  bottom: 5px;
  right: 5px;
  width: 50px;
  height: 50px;
  text-align: center;
  cursor: pointer;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 1005;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  -webkit-transition: all 0.2s ease-in-out;
  -o-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
  opacity: 0;
  filter: alpha(opacity=0);
}

.scrollToTop.fadeToTop {
  -webkit-animation-name: fadeToTop;
  animation-name: fadeToTop;
  -webkit-animation-duration: 0.4s;
  animation-duration: 0.4s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@-webkit-keyframes fadeToTop {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
  }

  100% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}

@keyframes fadeToTop {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    -ms-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
  }

  100% {
    opacity: 1;
    -webkit-transform: none;
    -ms-transform: none;
    transform: none;
  }
}

.scrollToTop.fadeToBottom {
  -webkit-animation-name: fadeToBottom;
  animation-name: fadeToBottom;
  -webkit-animation-duration: 0.4s;
  animation-duration: 0.4s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@-webkit-keyframes fadeToBottom {
  0% {
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    opacity: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
  }
}

@keyframes fadeToBottom {
  0% {
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    opacity: 0;
    -webkit-transform: translate3d(0, 100%, 0);
    -ms-transform: translate3d(0, 100%, 0);
    transform: translate3d(0, 100%, 0);
  }
}

.scrollToTop i {
  line-height: 48px;
  font-size: 26px;
}

.scrollToTop:hover {
  background-color: rgba(0, 0, 0, 0.6);
}

/* Small devices (tablets, phones less than 767px) */
@media (max-width: 767px) {
  .scrollToTop {
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.4);
  }

  .scrollToTop i {
    line-height: 40px;
    font-size: 20px;
  }
}

</style>

 

 

<!-- scrollToTop 시작 -->
<div class="scrollToTop circle fadeToTop">
		<i class="fa fa-angle-up"></i>
</div>
<!-- scrollToTop end -->

 

 

 

 

<script>
//Scroll totop
//-----------------------------------------------
$(window).scroll(function() {
	if($(this).scrollTop() != 0) {
		$(".scrollToTop").addClass("fadeToTop");
		$(".scrollToTop").removeClass("fadeToBottom");
	} else {
		$(".scrollToTop").removeClass("fadeToTop");
		$(".scrollToTop").addClass("fadeToBottom");
	}
});

$(".scrollToTop").click(function() {
	$("body,html").animate({scrollTop:0},800);
});

</script>

 

 

 

 

 

about author

PHRASE

Level 60  라이트

자식이건 부모이건 연고자이건 죽음을 만나 갈라지는 것을 구해줄 자는 그 누구도 없으리라. -법구경

댓글 ( 0)

댓글 남기기

작성

JQuery 목록    more