Ajaxulation question

Discussion in 'ASP .Net' started by Mr. SweatyFinger, Jan 22, 2007.

  1. 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?
    Mr. SweatyFinger, Jan 22, 2007
    #1
    1. Advertising

  2. Hi,

    Mr. SweatyFinger wrote:
    > 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
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
    Laurent Bugnion [MVP], Jan 22, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    591
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    646
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    943
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    417
    Philip Meyer
    Nov 30, 2003
  5. Mr. SweatyFinger

    I have an ajaxulation problem

    Mr. SweatyFinger, Jan 26, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    304
    Alexey Smirnov
    Jan 26, 2007
Loading...

Share This Page