如何檢查滾動條是否可見?是否可以檢查overflow:auto一個迪夫?例如:HTML<div id="my_div" style="width: 100px; height:100px; overflow:auto;" class="my_class">
* content</div>jQuery$('.my_class').live('hover', function (event){
if (event.type == 'mouseenter')
{
if( ... if scrollbar visible ? ... )
{
alert('true'):
}
else
{
alert('false'):
}
}});有時內(nèi)容短(沒有滾動條),有時長(滾動條可見)。
3 回答

12345678_0001
TA貢獻1802條經(jīng)驗 獲得超5個贊
(function($) { $.fn.hasScrollBar = function() { return this.get(0).scrollHeight > this.height(); }})(jQuery);
$('#my_div1').hasScrollBar(); // returns true if there's a `vertical` scrollbar, false otherwise..
body
演示
clientHeight
return this.get(0).scrollHeight > this.get(0).clientHeight;

浮云間
TA貢獻1829條經(jīng)驗 獲得超4個贊
if ($(document).height() > $(window).height()) { // scrollbar}

呼喚遠方
TA貢獻1856條經(jīng)驗 獲得超11個贊
Element.scrollHeight
Element.clientHeight
這個 元素,滾動體只讀屬性是對元素內(nèi)容高度的度量,包括由于溢出而在屏幕上不可見的內(nèi)容。 SCROLLLHL.8值等于元素所需的最小clientHight值,以便在不使用垂直滾動條的情況下適應(yīng)視點中的所有內(nèi)容。它包括元素填充,但不包括其邊距。
這個 元素、客戶體重只讀屬性返回元素的內(nèi)部高度(以像素為單位),包括填充,但不返回水平滾動條高度、邊框或邊距。
客戶端高度可以計算為CSS高度+CSS填充-水平滾動條的高度(如果有)。
function scrollbarVisible(element) { return element.scrollHeight > element.clientHeight;}
- 3 回答
- 0 關(guān)注
- 413 瀏覽
添加回答
舉報
0/150
提交
取消