Is detecting scrollbar presence with jQuery still difficult?

后端 未结 1 1473
眼角桃花
眼角桃花 2020-12-10 22:18

I know that detecting scrollbar presence is supposed to be one of those elusive things that we should all have to suffer through. What I\'ve read so far is that you can\'t r

1条回答
  •  爱一瞬间的悲伤
    2020-12-10 22:37

    Probably not as elegant as you were hoping for but this is an adequate adaption from a script I recently wrote to calculate viewport height.

    Logically you'd want to call this function on document ready and window resize.

    It also deals with inconsistencies that you'd encounter in Opera (line 2) and IE7 (line 6).

    function scrollbar() {
        var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
    
        if (jQuery.browser.msie) {
            if(parseInt(jQuery.browser.version) == 7) {
                viewportHeight -= 3;
            }
        }
    
        if(viewportHeight <= $('#wrapper').height()) {
            return true;
        } else {
            return false;
        }
    }
    

    0 讨论(0)
提交回复
热议问题