Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid blinking when updating page from ajax

Tags:

html

ajax

I've got a table with a header, a row with input fields, rows with data. Like this. http://brow.hu/sitegen/stackoverflow_table_example.png

If somebody enters something into an input field I want to filter the data with an ajax query. After receiving the new table I change the content of the old one: div.innerHTML = req.responseText; and it blinks. How to avoid that?

like image 318
Zoltan Lengyel Avatar asked Oct 12 '08 22:10

Zoltan Lengyel


1 Answers

One way to avoid flicker is called double-buffering. In Ajax, this can be done simply with 2 divs occupying the same space, one of them with the style 'display: none', the other 'display: inline'. Always write to the invisible one, and then swap display styles. If the divs have absolute positioning and size, there is absolutely no chance for flicker, and even if they don't, you can hardly do better.

like image 200
Alan Hensel Avatar answered Sep 28 '22 15:09

Alan Hensel