动态检测滚动条
Detect scrollbar dynamically
以下代码有什么问题?
我需要根据另一个元素是否有滚动条来检测和设置1个元素的宽度。这似乎不起作用:
console.log("print Scroll..here...");
if(($(".printer-details-container").offsetHeight < $(".printer-details-container").scrollHeight) || ($(".printer-details-container").offsetWidth < $(".printer-details-container").scrollWidth)){
// your element have overflow
console.log("print Scroll..here...");
$(".printer-header").css({"width":"96.9999%;"});
}
else{
//your element don't have overflow
console.log("no print Scroll..here...");
$(".printer-header").css({"width":"100%;"});
//console.log($(".printer-header").print-header.css({"width":"100%;"});
}
看看这个:
https://jsfiddle.net/4Lms5uzz/
首先,第二个div设置为50乘50。
如果#rulesdiv中存在滚动,则第二个的维度将发生更改。
基本上方法是divWithScrollbar.clientHeight < divWithScrollbar.scrollHeight
scrollHeight获取div内部内容的高度,clientHeight获取div.的大小
如果scrollHeight小于scrollHeith,则滚动条可见。
相关文章:
- 如何检测用户是否移动了滚动条
- 检测垂直滚动和滚动条宽度,并将宽度更改应用于正文
- 如何检测本机滚动条的按钮单击事件
- 检测 DIV 是否有滚动条
- 最终任务,如果可能的话,在Javascript中查找,通过单击滚动条来检测页面滚动
- 检测滚动条的存在
- 删除并检测小滚动条
- 如何跨浏览器检测(并纠正?)各种滚动条可见性
- 检测浏览器滚动条上的鼠标按下/单击事件
- 动态检测滚动条
- 如何检测是否有水平滚动条
- 如何检测引导模态滚动条的位置
- Javascript检测滚动条不工作
- 如何检测浏览器窗口中是否存在滚动条
- 特征检测-狮子滚动条
- 检测iFrame JS中的滚动条
- 如何检测滚动条'
- 如何检测浏览器窗口上是否有滚动条?
- 检测没有滚动条的页面上的滚动
- javascript滚动条检测