jQuery.scrollLeft() when direction is rtl - different values in different browsers

前端 未结 2 898
既然无缘
既然无缘 2020-12-19 10:39

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

相关标签:
2条回答
  • 2020-12-19 10:50

    Although I was hoping to avoid that, I ended up using browser detection:

    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 讨论(0)
  • 2020-12-19 11:03

    Browser incompatibilities. Try this

    0 讨论(0)
提交回复
热议问题