문제

I have a fixed topbar on my site, and I'm adding a padding-top to the body element based on the topbar height.

$('body').css('padding-top', $('.topbar').height());

But when I resize window and topbar becomes heigher the above jQuery code is not working until I refresh the page on desired viewport.

How to detect the topbar height live, even when window is resized?

Any help very appreciated!

도움이 되었습니까?

해결책

jQuery has a .resize() event. So you could try:

 $( window ).resize(function() {  

 $('body').css('padding-top', $('.topbar').height());

 });

If this doesn't work, make a fiddle and we can have a look at how your page is working.

다른 팁

You need to listen for a resize event:

$(window ).resize(function() {
    $('body').css('padding-top', $('.topbar').height());
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top