CSS: .blue { width:200px; height:200px; background-color:blue; color:#000000; overflow:auto; }JavaScript的:function addChar() { $('.blue').append('some text ');}HTML:<div id='blue1' class="blue"></div><br /><a href='javascript:void(0)' onclick='addChar()'>Add</a>div id='blue1'有overflow屬性設置為auto。我想在發生溢出時檢測溢出。
3 回答

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
$.fn.HasScrollBar = function() {
//note: clientHeight= height of holder
//scrollHeight= we have content till this height
var _elm = $(this)[0];
var _hasScrollBar = false;
if ((_elm.clientHeight < _elm.scrollHeight) || (_elm.clientWidth < _elm.scrollWidth)) {
_hasScrollBar = true;
}
return _hasScrollBar;
}
///這是我的解決方案

手掌心
TA貢獻1942條經驗 獲得超3個贊
針對具體問題的單線解決方案:
var elt, hasOverflow = (elt = $('#blue1')).innerWidth() > elt[0].scrollWidth;
只是想打高爾夫球。:]
(注意:這僅適用于水平溢出檢測;添加垂直溢出檢測也很簡單。)
- 3 回答
- 0 關注
- 545 瀏覽
添加回答
舉報
0/150
提交
取消