Ajaxulation question

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?
 
L

Laurent Bugnion [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top