本文介绍了如何确定隐藏/溢出文本是在元素的顶部还是底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想扩展Shog9的答案
I'd like to expand on Shog9's answer in
我想知道隐藏的文本是在包含元素的顶部还是底部(或者两者都没有,或者没有).
And I'd like to know if the text that is hidden is at the top or at the bottom (or both or none) of the containing element.
最好的方法是什么?
推荐答案
我看不到穿过树林的森林.Joel的代码段 var isScrolledDown = el.scrollTop>0;
使我意识到该怎么做.我使用了两个功能:
I could not see the forest through the trees. Joel's code snippet var isScrolledDown = el.scrollTop > 0;
made me realize how to do it. I used two functions:
function HasTopOverflow(el) {
return el.scrollTop;
}
function HasBottomOverflow(el) {
var scrollTop = el.scrollTop,
clientHeight = el.clientHeight,
scrollHeight = Math.max(el.scrollHeight, clientHeight);
return (scrollTop + clientHeight) < scrollHeight;
}
还没有测试它是否可以在IE6 +上运行,但是FF可以工作.
Haven't tested if it'll work on IE6+ yet, but FF works.
如果有任何错误,请告诉我.
If there are any bugs, please let me know.
这篇关于如何确定隐藏/溢出文本是在元素的顶部还是底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!