Is there a problem with scrollTop in Chrome?

Posted by Shaun on Stack Overflow See other posts from Stack Overflow or by Shaun
Published on 2010-03-30T12:15:36Z Indexed on 2010/03/30 14:13 UTC
Read the original article Hit count: 707

Filed under:
|

I am setting scrollTop and scrollLeft for a div that I am working with.

The code looks like this:

div.scrollLeft = content.cx*scalar - parseInt(div.style.width)/2;
div.scrollTop = content.cy*scalar - parseInt(div.style.height)/2;

This works just fine in FF, but only scrollLeft works in chrome. As you can see, the two use almost identical equations and as it works in FF I am just wondering if this is a problem with Chrome?

Update: If I switch the order of the assignments then scrollTop will work and scrollLeft won't.

 <div id="container" style = "height:600px; width:600px; overflow:auto;" onscroll = "updateCenter()">
<script>
    var div = document.getElementById('container');

    function updateCenter()
    {
        svfdim.cx = (div.scrollLeft + parseFloat(div.style.width)/2)/scalar;
        svfdim.cy = (div.scrollTop + parseFloat(div.style.height)/2)/scalar;
    }

    function updateScroll(svfdim, scalar, div)
    {
        div.scrollTop = svgdim.cy*scalar - parseFloat(div.style.height)/2;  
        div.scrollLeft = svgdim.cx*scalar - parseFloat(div.style.width)/2;
    }

    function resizeSVG(Root)
    {
        Root.setAttribute("height", svfdim.height*scalar);
        Root.setAttribute("width", svfdim.width*scalar);    
        updateScroll(svgdim, scalar, div);
    }
</script>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-chrome