0

I have a fluid div with relative positioning. Inside this div I have a timeline which consists of several labels indicating time. When scrollbar appears I need to refresh the positioning of timeline. But the only event I can think of is:

$(window).resize(function(event) {
    ...
});

and it doesn't fire. It fires only if I press, for example, f12 in chrome in order to open development tools. But if I get scrollbar in natural way (because a lot of content) I can't figure out how to catch this event

Victor
  • 5,073
  • 15
  • 68
  • 120
  • duplicate of this I quess: http://stackoverflow.com/questions/2578046/scrollbar-appear-disappear-event-in-jquery – Bob Claerhout Sep 23 '13 at 18:55
  • 1
    That's because .resize() only fires when the entire visible window is resized, for example when Chrome's developer tools are shown. The proper way to do this would be to run a check whenever you populate the div. – Hod - Monica's Army Sep 23 '13 at 18:56
  • Well, I dont populate div. But the size of div changes if scrollbar appears – Victor Sep 23 '13 at 19:06
  • Possible duplicate of [Detect when window vertical scrollbar appears](http://stackoverflow.com/questions/2175992/detect-when-window-vertical-scrollbar-appears) – user Apr 16 '17 at 10:13

1 Answers1

1

I made a jsfiddle showing how much the width of the body and a random div changes when the vertical scrollbar appears. This can help you solving your issue.

http://jsfiddle.net/kasperfish/GrZp4/3/

$(function() {
    getinfo();
    $('#togglescroll').click(function(){
        $('#container').slideToggle( "fast" , function (){
            getinfo();
        });

    });
});



function getinfo(){
     $('#view').html('body width: '+$("body").width()+'</br>');
     $('#view').append('red rectangle width: '+$("#view").width()+' (2px < body because of border 1px)</br>'); 
    if ($("body").height()>$(window).height()) {
        $('#view').append('vertical scrollbar: yes');        
    }else{
        $('#view').append('vertical scrollbar: no'); 
    }

}
kasper Taeymans
  • 6,950
  • 5
  • 32
  • 51
  • 1
    Actually I solved my issue in another way. I forget about something in my window resize event (I had an condition inside it) and thought that the event doesn't fire. Well, I refresh my absolute positioned divs on window.resize and don't care about scrollbar. But anyway thanks for your post, good to know – Victor Sep 24 '13 at 09:13