채택완료

스크롤 메뉴 질문합니다.

Copy
$('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개

채택된 답변
+20 포인트

Copy
$('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;

              }

        });

});

답변을 작성하려면 로그인이 필요합니다.

🐛 버그신고