Comments (6)
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.
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.
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.
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.
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.
See Pull Request #23.
from jail.
Related Issues (20)
- Would this plugin work for background-images? HOT 1
- iOS scroll issue HOT 3
- Visible images doesn't load in desktop browsers if image height is not set HOT 1
- Reloading the images causes an 'undefined' error HOT 3
- JAIL doesn't load images (outside the browser viewport) until scroll event HOT 2
- Update jail.min.js
- How to apply the plugin to images that are initially hidden when the page loads
- Updating to jquery 1.9.1 speed issue HOT 2
- click events still require scrolling to load image HOT 2
- I try to use jail on mobile
- Bad performance
- same image twice
- How to use cache to not reload the images from scratch once the page is loaded
- Handheld devices HOT 3
- required negative callback and image-on-fail
- summary details component is broken HOT 1
- Translations updated
- Still loads hidden images
- want to load first image then display remaining image while scrolling
- Performance issue we are facing with Android
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jail.