使用JavaScript检测水平div溢出? [英] Detecting horizontal div overflow with JavaScript?

查看:76
本文介绍了使用JavaScript检测水平div溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DIV,里面有很多子DIV.我想要的类似于Firefox的选项卡,当打开的选项卡太多或主DIV宽度太小时,界面将检测到溢出并在右侧显示一个按钮以列出所有隐藏的选项卡.问题是我什至不知道从哪里开始寻求帮助.

I have a DIV that has plenty of child DIVs inside of it. What I want is similar to Firefox's tabs, when you have too many tabs open or the main DIV width is too small, the interface will detect overflow and show a button on the right side to list all hidden tabs. The problem is that I have no idea where to even start looking for help.

推荐答案

您是否将主DIV设置为 overflow:hidden ?

Is you main DIV set to overflow:hidden?

如果是这样,可以通过增加 scrollLeft 属性并查询它是否已更改来测试其是否溢出:

If so, you can test its need to overflow by incrementing the scrollLeft property and then querying it to see if it's changed:

function containsTooMuch(el) {
    var original = el.scrollLeft++;
    return el.scrollLeft-- > original;
}

这篇关于使用JavaScript检测水平div溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆