2012-07-23 2 views
5

body 방향이 rtl 인 경우 div의 scrollLeft 속성이 다른 브라우저에서 다른 값을 반환하는 것처럼 보입니다. 초기 값은 400이고, 왼쪽으로 스크롤 이동 때 IE8 0방향이 rtl 인 경우 jQuery.scrollLeft() - 다른 브라우저에서 다른 값

인 - - 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()); 
    }); 
});​ 

크롬 -

예는 여기에서 알 수있는 0

- 0 및 -400.

이 차이의 원인은 무엇이며 어떻게 처리 할 수 ​​있습니까?

편집 : "일반"scrollLeft에서도 마찬가지입니다. document.getElementById("divContainer").scrollLeft은 같은 결과를 반환합니다.

답변

4

을 시도, 내가 브라우저 감지를 사용하여 종료 :

function GetScrollLeft(elem) 
{ 
    var scrollLeft = elem.scrollLeft(); 
    if ($("body").css("direction").toLowerCase() == "rtl") 
    { 
     // Absolute value - gets IE and FF to return the same values 
     var scrollLeft = Math.abs(scrollLeft); 

     // Get Chrome and Safari to return the same value as well 
     if ($.browser.webkit) 
     { 
      scrollLeft = elem[0].scrollWidth - elem[0].clientWidth - scrollLeft; 
     } 
    } 
    return scrollLeft; 
} 
+0

브라우저 탐지 자체가 나쁜 것은 아니다, IE이다. – jbkkd

+0

나는 또한이 문제와 싸우고있다 .... 카나리아 고정 scrollLeft, 그러나 scrollIntoView() http://plnkr.co/edit/UZvnlq?p=info – Jason

0

브라우저 비 호환성. 나는 그것을 피하기 위해 바라고 있지만 this

관련 문제