// top 버튼
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$(".btn_top").fadeIn();
}
else {
$(".btn_top").fadeOut();
}
});
$(".btn_top").click(function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
위 코드는 조금 자잘한 문제들이 있음.
아래 코드가 반응이 더 빠르고, 부드럽게 이동함.
// top 버튼
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$(".btn_top").fadeIn();
}
else {
$(".btn_top").fadeOut();
}
});
$(".btn_top").click(function () {
$('html, body').animate({
scrollTop: 0
}, 1000)
});'Publish > JavaScript' 카테고리의 다른 글
| 모바일 팝업창 모달창 알림창 (0) | 2022.06.20 |
|---|---|
| [문제 해결] 스크롤 해서 맨 아래 도달시 스크립트 이벤트 활성화 하기 (0) | 2022.06.20 |
| 스와이퍼 슬라이드 hover 시 stop 하는 스크립트 (0) | 2022.06.08 |
| 체크박스 all 전체선택 전체해제 (0) | 2022.05.25 |
| [ input ] 회원가입 form 필수입력 표식 스크립트 ( * ) (0) | 2022.04.11 |