티스토리 뷰
728x90
반응형
jQuery를 사용하여 특정 selector 위치로 스크롤 이동시키기
const selectorTop = $('selector').offset().top; // selector 좌표 top
const headerHeight = $('.header').height; // 제외할 헤더 높이
$('html, body').stop().animate({scrolltop : selectorTop - headerHeight}); // 스크롤 이동
JavaScript로도 구현 가능
document.gelElementById('id').scrollIntoView({behavior:"smooth"}); //IE, Safari behavior 옵션 사용 불가
728x90
반응형
'Javascript' 카테고리의 다른 글
Intersection Observer 이미지 지연 로딩 (0) | 2023.07.06 |
---|---|
script 태그 위치 (0) | 2022.09.07 |
javascript에서 Timer, Countdown 서버 시간 동기화 (0) | 2022.03.24 |
https 프로토콜 iframe 주의 (0) | 2021.07.19 |
setTimeout() (0) | 2020.12.23 |
반응형
300x250