The scrollLeft property of a div seems to return different values in different browsers when the body direction is rtl.
An example can be seen here - http://jsfiddle.net/auVLZ/2/
body { direction: rtl; }
div.Container { border: 5px solid #F00; width: 500px; height: 400px; overflow: auto; }
div.Content { background-color: #00F; width: 900px; height: 380px; }?
<div id="divContainer" class="Container">
<div class="Content"></div>
</div>
<br />
<input id="showScrollLeft" type="button" value="Show ScrollLeft" />?
$(document).ready(function()
{
$("#showScrollLeft").click(function(e)
{
alert($("div.Container").scrollLeft());
});
});?
Chrome - the initial value is 400, and when moving the scrollbar to the left it is 0.
IE8 - 0 and 400.
Firefox - 0 and -400.
What is causing this difference and how can it be handled?
Edit: note that this is happening with the "regular" scrollLeft as well - document.getElementById("divContainer").scrollLeft
returns the same results.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…