1

In a html page I am making, I dynamically move images into the viewport using jQuery and Raphael's library. When I refresh the webpage, these images appears to be white block for <100ms before the webpage loads again. I want to move these images out of the viewport so these white blocks don't appear.

I used window.onbeforeuload=functio(){$('#myimge").css(...);} to move the image. But it turns out that the white blocks still appear because the browser doesn't have time to show a newly refreshed view with the images in the new location. If I put alert(), then the images will disappear. So I am looking a way to really move the images out of the browser window before the browser reloads the page.

Hai Bi
  • 1,173
  • 1
  • 11
  • 21

1 Answers1

1

You can't do that, you can't block window from closing, unless you hack it, but it's very bad practise i think

$(window).on('beforeunload', function() {
     var start = +new Date;
     while ((+new Date - start) < 3000);                        
 }); 

For me i would go with ajax loaded pages, more like HTML5 pages

Omiga
  • 572
  • 3
  • 11