如何检测滚动条的一侧?

如何检测滚动条的一侧?

问题描述:

我在页面上有一个带溢出的div:可见方向:rtl
问题是IE显示左侧的滚动条,而Chrome和FF显示右侧的滚动条。
是否有任何js方法可以检测滚动条的一侧?

I have a div with overflow:visible and direction:rtl on a page. The problem is that IE shows the scroll bar on the left while Chrome and FF shows it on the right. Is there any js way to detect the side of the scroll bar?

我知道你可以选择IE浏览器左侧和其他所有它在右边,但我对这个解决方案不满意

I know that you could go with if IE it's on the left and all others it's on the right, but I'm not happy with this solution

这是一个非常愚蠢的想法:

Here's a really hacky idea:

获取div中第一个子元素的相对x偏移量(或者简单地从孩子的x位置减去div的x位置)

Get the relative x-offset of the first child element inside the div (or simply subtract the div's x-position from the child's x-position)

如果滚动条在左侧,则第一个子项的x-offset / -position应该高于右侧栏的值,因为左侧滚动条会将元素向右推动一点。

If the scrollbar is on the left, the first child's x-offset/-position should be higher than if the bar's on the right, since a left-hand scrollbar would push the element a bit to the right.

也许它会起作用(我没有IE方便检查它)

Maybe it'll work (I don't have IE handy to check it)

这是一个未经测试的jsfiddle这个概念: http://jsfiddle.net/tKGS2/

Here's an untested jsfiddle of the concept: http://jsfiddle.net/tKGS2/