jQuery预加载仅适用于刷新时的ie
jQuery preload only works with ie on refresh
我遇到了ie9不总是加载预加载图像的问题。有时我尝试刷新页面,然后它就工作了。
$jQuery.fn.img_preloader = function(options){
var defaults = {
repeatedCheck: 550,
fadeInSpeed: 1100,
delay: 200,
callback: ''
};
var options = jQuery.extend(defaults, options);
return this.each(function(){
var imageContainer = jQuery(this),
images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
imagesToLoad = images.length;
imageContainer.operations = {
preload: function(){
var stopPreloading = true;
images.each(function(i, event){
var image = jQuery(this);
if(event.complete == true){
imageContainer.operations.showImage(image);
}else{
image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
}
});
return this;
},showImage: function(image){
imagesToLoad --;
if(image.data.currentImage != undefined) { image = image.data.currentImage;}
if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
if(imagesToLoad == 0){
if(options.delay > 0){
images.each(function(i, event){
var image = jQuery(this);
setTimeout(function(){
image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
},
options.delay*(i+1));
});
if(options.callback != ''){
setTimeout(options.callback, options.delay*images.length);
}
}else if(options.callback != ''){
(options.callback)();
}
}
}
};
imageContainer.operations.preload();
});
}
尝试对event.complete
验证进行注释并直接转到showImage事件。这不是最好的解决方案,但对我有效。
$jQuery.fn.img_preloader = function(options)
{
var defaults = {
repeatedCheck: 550,
fadeInSpeed: 1100,
delay: 200,
callback: ''
};
var options = jQuery.extend(defaults, options);
return this.each(function()
{
var imageContainer = jQuery(this),
images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
imagesToLoad = images.length;
imageContainer.operations = {
preload: function(){
var stopPreloading = true;
images.each(function(i, event){
var image = jQuery(this);
imageContainer.operations.showImage(image);
/*if(event.complete == true){
imageContainer.operations.showImage(image);
}else{
image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
}*/
});
return this;
},showImage: function(image){
imagesToLoad --;
if(image.data.currentImage != undefined) { image = image.data.currentImage;}
if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
if(imagesToLoad == 0){
if(options.delay > 0){
images.each(function(i, event){
var image = jQuery(this);
setTimeout(function(){
image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
},
options.delay*(i+1));
});
if(options.callback != ''){
setTimeout(options.callback, options.delay*images.length);
}
}else if(options.callback != ''){
(options.callback)();
}
}
}
};
imageContainer.operations.preload();
});
}
替换此showimage函数。。
showImage: function (g) {
d--;
if (g.data.currentImage != undefined) {
g = g.data.currentImage;
}
if (b.delay <= 0) {
g.css("visibility", "visible").animate({
opacity: 1
}, b.fadeInSpeed);
}
if (d != 0) {
if (b.delay != 0) {
e.each(function (k, j) {
var h = a(this);
setTimeout(function () {
h.css("visibility", "visible").animate({
opacity: 1
}, b.fadeInSpeed)
}, b.delay * (k + 1))
});
if (b.callback != "") {
setTimeout(b.callback, b.delay * e.length)
}
} else {
if (b.callback != "") {
b.callback()
}
}
}
}
相关文章:
- jQuery预加载仅适用于刷新时的ie
- 加载时刷新页面仅用于IE
- 刷新IE 9中的fb IFRAME-dos'不起作用
- HTML -刷新表单字段-在IE和Phone-android中的不同行为
- IE中部分页面刷新
- JavaScript刷新/重载页面不支持Safari和IE,但在Chrome和Firefox中工作良好
- Highcharts在IE<=9和Chrome上刷新后失去了它的's dateRange值
- jQuery模糊不能在IE中刷新页面
- 背景图像旋转问题在Chrome(只工作后的F5刷新).在FF, Safari, IE中没有问题
- 无法刷新IE浏览器的缓存
- IE中的下拉框在单击事件时不刷新
- 样式与媒体查询在ngView中IE工作后刷新
- 代码获胜'在我刷新之前不会在IE中显示
- 如何处理IE中多次刷新函数的框背景颜色
- 无法在MVC 4中关闭子窗口时刷新父视图!我正在使用IE 8
- IE 9不使用window.open刷新窗口,而是打开新窗口
- history.back() 在 IE 中没有页面刷新
- IE中的视差效果刷新率很糟糕
- 剑道UI网格不能在ie中自动刷新
- 在IE的一些JS中,Jquery代码在开始时不工作,但在刷新页面2-3次之后.任何想法