views:

57

answers:

1

I'm trying to create some kind of zoom around the mouse cursor feature on my website which ultimately runs these two lines (+ the same for height/scrollTop).

canvas.style.width = someValue;
canvas.parentNode.scrollLeft = someOtherValue;

The problem is that in firefox(3.6) the page is re-rendered directly after the first row has been executed and since the view is depending on both values this means that every time i recalculate the view firefox will will render an invalid view before the correct one, in other words creating flicker.

I've tried swapping the two rows but get the same problem.

In chrome, opera and IE this doesn't happen. Both lines are executed before any rendering is done.

Is there any way to lock the rendering manually, maybe something like this?

document.disableRendering();        //fantasy function
canvas.style.width = someValue;
canvas.parentNode.scrollLeft = someOtherValue;
document.enableRendering();         //fantasy function
+1  A: 

A common way to avoid this is to set .display = 'none'; while doing the DOM manipulation.

Sean Kinsey
But wouldn't it trigger another repaint?
el.pescado
Does not work in this case because if you set display:none the canvas width will be zero and there's no way to set scrollWidth on the parent.
Erik
The question doesn't really mention that :)
Sean Kinsey
I tried to add a different canvas without any content in the parent and set the same width/height for this one and only set display:none on the one with content, this way there is still content to scroll and you can set the scrollLeft on the parent. The bad thing is that this causes a repaint as el.pescado said and you will get one flash without any content but it's still better than a render with the content in wrong position.(I meant scrollLeft in the comment above btw)
Erik