Ajaxulation question

  • Thread starter Thread starter Mr. SweatyFinger
  • Start date Start date
M

Mr. SweatyFinger

I want use ajax. I want to swap out my images smoothly without getting stuck
between pages.
Do I need to add ajaxulate on each picture, or ajaxulate on the whole
website?
 
Hi,

Mr. SweatyFinger said:
I want use ajax. I want to swap out my images smoothly without getting stuck
between pages.
Do I need to add ajaxulate on each picture, or ajaxulate on the whole
website?

Images do not need AJAX to get loaded or changed smoothly. With
JavaScript, setting the "src" property of the Image object is sufficient
to create a new HTTP Request for the image. In older browsers (Netscape
4), the image was sometimes not resized properly, but the new browsers
handle this without problems.

for example:

<img id="myImage" src="image1.jpg" alt="An image" />

var nImage = document.getElementById( "myImage" );
nImage.src = "image2.jpg";

If you additionally want the image to be "swapped" without any delay,
you can preload the image in the cache first. For example:

var cachedImage = new Image();

function swapImage()
{
var nImage = document.getElementById( "myImage" );
nImage.src = cachedImage.src;
}

cachedImage.onload = swapImage;
cachedImage.src = "image2.jpg";

With this code, the Http request is sent, the image sent back to the
browser. When the image is fully loaded, the onload event is fired, and
the image is swapped. Since the image is already in the browser's cache,
the swap is immediate.

No AJAX involved.

HTH,
Laurent
 
Back
Top