Giter Site home page Giter Site logo

Comments (6)

witq avatar witq commented on September 17, 2024

Well, I might have found a solution. I changed the main image loading function to check if the $img is loaded before executing. Check it out and maybe you will find it usefull:

// Main function --> Load the images copying the "data-href" attribute into the "src" attribute
        _loadImage : function(options, $img) {

            $img.hide();
            $img.attr("src", $img.attr("data-href"));
            $img.removeAttr('data-href');

            // Check if image is loaded
            $img.load(function() {
                // Images loaded with some effect if existing
                if(options.effect) {
                    if (options.speed) {
                        $img[options.effect](options.speed);
                    } else {
                        $img[options.effect]();
                }
                } else {
                    $img.show();
                }

                // Callback after each image is loaded
                options.callbackAfterEachImage.call(this, $img, options);
            });

        }

from jail.

witq avatar witq commented on September 17, 2024

I guess it's not that easy, just tested it in IE 8 and random images are not loading on page refresh. Bummer.

from jail.

witq avatar witq commented on September 17, 2024

I have found a way to trigger the load event even if images are cached, this solves the problem with images not appearing in IE. This is my modified function:

// Main function --> Load the images copying the "data-href" attribute into the "src" attribute
        _loadImage : function(options, $img) {

            $img.hide();

            // Check if image has finished loading
            $img.attr('src', $img.attr('data-href')).one('load', function() {
                // Images loaded with some effect if existing
                if(options.effect) {
                    if (options.speed) {
                        $img[options.effect](options.speed);
                    } else {
                        $img[options.effect]();
                    }
                } else {
                    $img.show();
                }

                // Callback after each image is loaded
                options.callbackAfterEachImage.call(this, $img, options);

            // Make shure the load event is triggered even if image is already in cache
            }).each(function(){
                if(this.complete || this.complete == undefined) 
                $(this).trigger('load');
            });

            $img.removeAttr('data-href');

        }

from jail.

philoye avatar philoye commented on September 17, 2024

Knowing when images have loaded is a hard problem.

Here's a jQuery library originally created by Paul Irish which has had a lot of work. It still has some quirks, but probably the best thing out there, and probably worth using.

from jail.

humancopy avatar humancopy commented on September 17, 2024

It's not so difficult. :)

Need to make sure the onload is assigned before assigning the source to an Image object, then it is always called even if the image is in the browser's cache already.

Please see commit humancopy/JAIL@42f76ed

from jail.

sebarmeli avatar sebarmeli commented on September 17, 2024

See Pull Request #23.

from jail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.