Recent Posts
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
관리 메뉴

I AM EVERYTHING

[jQuery] 일정 높이만큼 스크롤시 fixed 본문

programming

[jQuery] 일정 높이만큼 스크롤시 fixed

박꽁냥 2018. 9. 3. 13:03

var gnbLoc = 570; // 스크롤 값

  $(window).scroll(function() {

    var winLoc = $(window).scrollTop();

    if (winLoc > gnbLoc) {

      $('.title').addClass('scroll');

      $('.content').css('padding-top', '47px'); // title 높이 값

    } else if (winLoc <= gnbLoc) {

      headerLoc = (gnbLoc - winLoc); //37,36,35,34.....0,-1,-2...

      $('.title').removeClass('scroll');

      $('.content').css('padding-top', '0');

    }

  });

});


scroll이란 클래스에 position: fixed를 비롯해 변화되는 값 주기



Comments