How to resize navbar logo on scroll down

前端 未结 4 980
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 10:56

So I have this navbar with a logo on it. I would like the logo to be big when the user is in the header section of the page, but then shrink when the user scrolls down. Any

4条回答
  •  北海茫月
    2020-12-28 11:39

    You can achieve this using JQuery-

    $(document).scroll(function() {
        $('#navbar').css({width: $(this).scrollTop() > 100? "50%":"100%"});
    });
    

    explanation- When scrolling- get the navbar element, change it's CSS as follows: if scrollTop() < 100 (we're not at the top of the page) - change the width to 50%. Otherwise change it to 100% (regular)

提交回复
热议问题