스크롤 메뉴 질문합니다.

스크롤 메뉴 질문합니다.

QA

스크롤 메뉴 질문합니다.

답변 1

본문


$('header').mouseenter(function () {
        $(this).addClass('wbg');
    })
 
    $('header').mouseleave(function () {
        $(this).removeClass('wbg');
    })
 
    jQuery(document).ready(function () {
        var bodyOffset = jQuery('body').offset();
       
        jQuery(window).scroll(function () {
            if (jQuery(document).scrollTop() > bodyOffset.top) {
                jQuery('header').addClass('wbg');
            } else {
                jQuery('header').removeClass('wbg');
            }
        });
    });

 

 

위 코드를 사용해서

마우스가 헤더를 건들이면 wbg 클래스가 추가되게 했습니다.

그리고 스크롤시에도 wbg 클래스가 추가되게 했습니다.

문제가 스크롤 내렸을때 헤더를 건드리고 나오면 wbg 가 사라지더라구요

혹시 이거 두개 합쳐서 어떻게 하는지 알수 있을까욤?ㅠㅠ

이 질문에 댓글 쓰기 :

답변 1


$('header').mouseenter(function () {
  $(this).addClass('wbg');
})
 
$('header').mouseleave(function () {
  if($cond == 0){
    $(this).removeClass('wbg');
  }
})
var $cond = 0;
jQuery(document).ready(function () {
    var bodyOffset = jQuery('body').offset();
        jQuery(window).scroll(function () {
              if (jQuery(document).scrollTop() > bodyOffset.top) {
                jQuery('header').addClass('wbg');
                $cond = 1;
              } else {
                jQuery('header').removeClass('wbg');
                $cond = 0;
              }
        });
});
 
 
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,100
© SIRSOFT
현재 페이지 제일 처음으로