jquery - 使用 jquery 检测元素溢出

标签 jquery

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。我想在溢出发生时检测到它。

最佳答案

$.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;
}

///这是我的解决方案

关于jquery - 使用 jquery 检测元素溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2059743/

相关文章:

javascript - 如何使用jquery将表中的数据导出到csv文件

javascript - 隐藏 <section> 末尾的 div

javascript - 使用 jquery 和 ajax 获取 rss feed

javascript - 使用 jQuery 检测用户何时不关注输入框?

php - 根据请求获得包含大量结果的页面的最有效方法

jquery对齐进度条

jquery - 如何让一些文字反复显示和隐藏?

javascript - 如何跨多个选项卡维护登录 session ?

javascript - JqueryUI 工具提示阻止 <select> 元素下拉列表在 IE 11 中停留

javascript - jQuery : Finding the select elements inside the table row and listening to change event