开发者

How to detect scroll bar's side?

开发者 https://www.devze.com 2023-03-25 18:46 出处:网络
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.

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?

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 solut开发者_JAVA百科ion


Here's a really hacky idea:

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)

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.

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

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


<div style="overflow:auto; width:100px; height:100px">
    <div style="direction:rtl;">
        text text text text text text text text text text 
        text text text text text text text text text text 
        text text text text text text text text text text
    </div>
</div>


I made it so you could get the scrollbar position from javascript without having to have visible div http://jsfiddle.net/tKGS2/27/

var d = $("<div></div>");
d.css("overflow-y","scroll");
d.append('<p/>');

$('#pivot').append(d);

var x = d.find('p').position().left
d.css('display','none');

document.body.innerHTML += x;
var pos = x < 3 ? "right" : "left";
document.body.innerHTML += pos;
0

精彩评论

暂无评论...
验证码 换一张
取 消