How can I check if a scrollbar is visible?

后端 未结 19 2796
情话喂你
情话喂你 2020-11-22 14:39

Is it possible to check the overflow:auto of a div?

For example:

HTML

19条回答
  •  余生分开走
    2020-11-22 15:20

    Here's my improvement: added parseInt. for some weird reason it didn't work without it.

    // usage: jQuery('#my_div1').hasVerticalScrollBar();
    // Credit: http://stackoverflow.com/questions/4814398/how-can-i-check-if-a-scrollbar-is-visible
    (function($) {
        $.fn.hasVerticalScrollBar = function() {
            return this.get(0) ? parseInt( this.get(0).scrollHeight ) > parseInt( this.innerHeight() ) : false;
        };
    })(jQuery);
    

提交回复
热议问题