728x90
반응형
제이쿼리(jQuery)를 이용하여 스크롤(scroll) 감지 이벤트 만들기
스크롤 시 배경색 변경 예시
[html]
<div class="menu">main menu</div>
<div class="container"></div>
[css]
.menu{
position: fixed;
top: 0;
width: 100%; height: 40px;
background: pink;
}
.menu.active{
background: blue;
color: #fff;
}
.container{
width: 100%; height: 800px;
}
[js]
$(document).on('scroll', function(){
if($(window).scrollTop() > 100){
$('.menu').addClass('active');
}else{
$('.menu').removeClass('active');
}
});
See the Pen [jQuery] scroll _ 스크롤 감지 이벤트 by Jinsik Son (@Jinsik-Son) on CodePen.
'jQuery' 카테고리의 다른 글
[jQuery] 팝업(popup) / 모달(Modal) 시 스크롤 비활성화 (iOS 포함 모든 기기) (0) | 2023.07.25 |
---|---|
[jQuery] 아이폰(iOS) 사파리 바운스 스크롤(bounce scroll) 대응 헤더 (0) | 2023.06.16 |
[jQuery] 스크롤(scroll) 방향 감지 이벤트 (0) | 2023.06.14 |
[jQuery] img 태그 경로(src) 변경 (0) | 2023.06.07 |
[jQuery] 마우스 오버(hover) 내려오는 드롭 메뉴 (0) | 2023.06.06 |