블로그 · 2023년 4월 27일 · 읽기 1분
스크롤 이동 버튼
$('.targetBtn').on('click', function (e) { e.preventDefault(); let scrollPosition = $(targetArea).offset().top; $('html, body').animate({ scrollTop: scrollPosition }, 10); });
- 파라미터 값에 따라 스크롤 이동
function getParameterByName(name) { var url = new URL( window.location.href;) if (!url.search) return ''; if (!url.search.includes(name)) return ''; return decodeURIComponent(url.search.split('=')[1]); } window.onload = function () { var scrollTo = getParameterByName('scrollTo'); if (scrollTo.includes('kcks')) { $('html, body').animate({ scrollTop: $('#targetKcks').offset().top - 60 }, 10); } if (scrollTo.includes('tshirts')) { $('html, body').animate({ scrollTop: $('#targetTshrits').offset().top - 60 }, 10); } }