Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:38:39+00:00 2026-06-09T01:38:39+00:00

I am using this script… It load content from a specifc #id in a

  • 0

I am using this script…

It load content from a specifc #id in a URL to current page, and animate it… sliding from side of the page…when user click on a link

Everything works except images taking time to load… I tried and struggling to incorporate image preloader to this? So all the content loads together

function goTo(href) {

    var left = $(window).width();
    $('#id').css("left", left);

    $.ajax({
        url: href,
        success: function (data) {

            var content = $(data).find('#id').html();

            // Windows Load Function
            $(window).load(function () {

                $("#id").html(content).animate({
                    left: '0',
                }, 'fast');

                var title = $('#id').find('h1').text();
                $('head').find('title').text(title);

            });
        }
    });
}

// check for support before we move ahead

if (typeof history.pushState !== "undefined") {
    var historyCount = 0;

    // On click of link Load content and animate
    $('.access a').live('click', function () {

        var href = $(this).attr('href');

        goTo(href);

        history.pushState(null, null, href);
        return false;
    });

    window.onpopstate = function () {
        if (historyCount) {
            goTo(document.location);
        }
        historyCount = historyCount + 1;
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:38:42+00:00Added an answer on June 9, 2026 at 1:38 am

    The window load event only happens once. What you will want to do is parse the content into an html fragment, loop through and preload the images, and then append the content.

    // this contains the content we want to append
    var $content = $(data).find('#id').children();
    // these are the images that are in content that we need to preload
    var $images = $content.find("img").add($content.filter("img"));
    // keep track of successfully preloaded images
    var counter = 0;
    // deferred object that will resolve when all images are preloaded
    var $def = $.Deferred();
    $images.each(function(){
        // if image is already loaded, increment counter and move on.
        if (this.complete || this.readystate === 4) {
            counter++;
            // if all images are preloaded, resolve deferred object
            if (counter === $images.length) $def.resolve();
        }
        else {
            // since the image isn't already preloaded, bind the load event.
            $(this).load(function(){
                counter++;
                // if all images are preloaded, resolve deferred object
                if (counter === $images.length) $def.resolve();
            });
        }
    });
    // when done preloading, this function will happen.
    $def.done(function(){
        // empty target element and append content to it, then animate it.
        $("#id").empty().append($content)
            .animate({
                left: '0'
            }, 'fast');
    
        var title = $('#id').find('h1').text();
        $('head').find('title').text(title);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my site i want to set default page to open, using this script
I am using this script : http://www.morethannothing.co.uk/wp-content/uploads/2010/01/placeholder.js to get some placeholders into IE. Works
I'm using this script to switch layouts in a page: $(span.switcher).click(function () { $(span.switcher).toggleClass(swap);
I am using this script to randomly load a style sheet on load. But
I am currently using this script to fade page transitions: $(document).ready(function() { $(window).bind(unload, function()
I'm using this script for building application from command line: #!/bin/bash TARGET=signtest CONFIGURATION=Debug SDK=iphoneos
I am using this zoom image script to load thumbs into larger images: http://www.eyecon.ro/zoomimage/#implement
I am currently using this script to get new data every second from record_count.php
I'm using this script that takes an url and modifies it. It stores the
I'm using this script that shows a little warning when a user clicks on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.