블로그 · 2022년 12월 16일 · 읽기 1분
jQuery scroll 이동 버튼
HTML
... ... <div class="introduce" id="eventArea"> 목적지 </div> ... ... <div class="scroll_event_area"> <button class="btn_scroll_event" data-target="#eventArea"> 이동하기 </button> </div>
jQuery
let $target_list = $('.scroll_event_area'); let $list_area = $target_list.find('.btn_scroll_event').data('target'); function targetScrollEvent2(targetBtn, targetArea) { targetBtn.on('click', function (e) { e.preventDefault(); let scrollPosition = $(targetArea).offset().top; $('html, body').animate({ scrollTop: scrollPosition }, 10); }); } targetScrollEvent($target_list, $list_area)