Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome gets fixed element replicated when scrolling

I am using chrome version 18.0.1025.162 m
I have html file with iframe within it.

i cant change the containing page or its css (main.htm)
i can only change the iframe (show.htm) and its css.

The problem is that when i scroll down and then scroll back up then the adminbar div get replicated several time.
I am attaching 2 screenshots the first one is the screen before scrolling and i also add the code so that the bug can be reproduced.

I think it may be a bug in chrome, i am not sure.
I would like to know if it is a a bug and more importantly if there is a work around by only changing the iframe and that it does not include removing the background color from the iframe.
(removing the background color from the iframe solve the issue but i need the background color)

so this is how it looks: before scrolling: enter image description here

after scrolling (admin bar get replicated on screen) enter image description here

now code to reproduce the bug in chrome

first file - main.htm (i cannot change this code)

<!-- main.htm -->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
#adminbar 
{
    background-color: #464646;
    height: 28px;
    position: fixed;
    width: 100%;
    top: 0;   
 }

 #body-content 
 {
    float: left;
    width: 100%;
 }
 </style>

 </head>
 <body >
 <div id="body-content">
    <iframe src="show.htm" width="100%" height="943"></iframe>

    <div id="adminbar" class="" role="navigation">
    </div>
 </div>

 </body>
 </html>

and the show.htm

<!-- show.htm -->
<!DOCTYPE html>
<head>
<style type="text/css">
body 
{
    background: #e0e0e0;
}
</style>
</head>
<body>
 <br/>
<p style='margin-bottom:500px;'>bazinga</p>
<p style='margin-bottom:500px;'>bazinga</p>
<p style='margin-bottom:500px;'>bazinga</p>
</body>
</html>
like image 239
yossi Avatar asked Apr 24 '12 13:04

yossi


3 Answers

i think i found a workaround. i created a file background.png which has one pixel with the color i want (#e0e0e0).

i then replace this:

body 
{
     background: #e0e0e0;
}

with this:

body 
{
    background: #e0e0e0 url(background.png) repeat-x;
    background-attachment: fixed;
}
like image 177
yossi Avatar answered Nov 18 '22 21:11

yossi


Add -webkit-transform: translate3d(0,0,0); to your body-content CSS

CSS

#body-content {
   float: left;
   width: 100%;
   -webkit-transform: translate3d(0,0,0);
}

This seems to force Chrome to use your GPU and smooth out the rendering issue.

UPDATE: Since you can't change main.htm, what about changing the background color of show.htm to a background image of the same color? I tested this and it worked. Is that a possibility?

like image 43
j08691 Avatar answered Nov 18 '22 22:11

j08691


I recreated your setup and then added a script to the body of show.htm. As a quick measure I added a name="if1" to the <iframe /> in main.htm, but you could always find a handle on the element without using an explicitly assigned name.

It seems to solve the issue for the dummy setup that you provided, if and only if main.htm is scrolled all the way to the top. Think it's weird, join the club! See if this works for the real thing... Either way, it may just be a nudge in the right direction! :)

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body 
{
    background: #e0e0e0;
}
</style>
</head>
<body>
<br/>
<p style="margin-bottom:500px;">bazinga</p>
<p style="margin-bottom:500px;">bazinga</p>
<p style="margin-bottom:500px;">bazinga</p>
<script type="text/javascript">
    window.onscroll = function(){
        console.log("It's 'Doctor' Sheldon Cooper!");
        //parent.document.if1.document.body.style.webkitTransform = 'scale(1)';
        var _parentScale = parent.document.body.style.webkitTransform;
        parent.document.body.style.webkitTransform = _parentScale;
    }
</script>
</body>
</html>​​​​​​​​​​​​​​​

I also tried to experiment with the following until it became bed-time!

<script type="text/javascript">
    window.onscroll = function(){
        console.log("It's 'Doctor' Sheldon Cooper!");
        //parent.document.if1.document.body.style.webkitTransform = 'scale(1)';
        var _me = document.body;
        _me.style.webkitTransform = _me.style.webkitTransform;
        //_me.style.display='none';
        _me.offsetHeight
        //_me.style.display='block';

        var _parent = parent.document.body;
        _parent.style.webkitTransform = _parent.style.webkitTransform;
        _parent.style.display=_parent.style.display;
        _parent.offsetHeight
        //_parent.style.display='block';
    }
    parent.window.onscroll = function(){
        console.log("But. You're in my spot!");
        //parent.document.if1.document.body.style.webkitTransform = 'scale(1)';
        var _me = document.body;
        _me.style.webkitTransform = _me.style.webkitTransform;
        //_me.style.display='none';
        _me.offsetHeight
        //_me.style.display='block';

        var _child = parent.document.if1.document.body;
        _child.style.webkitTransform = _child.style.webkitTransform;
        _child.style.display=_child.style.display;
        _child.offsetHeight
        //_child.style.display='block';
    }
</script>

I also attempted to apply j08691's answer, using the following script, but it gave slightly unexpected results. I caused the absolute positioned top bar, to not be fixed, among other things!

    window.onload = function(){
        console.log("It's 'Doctor' Sheldon Cooper!");
        var test = parent.document.getElementById("body-content");
        test.style.webkitTransform = "translate3d(0,0,0)";
    }

One may already exist, but if not, could you file this as a bug report on the relevent projects?

like image 2
bPratik Avatar answered Nov 18 '22 22:11

bPratik