8

我有需要绝对定位的图像,以便图像的中心位于其父 div 的中心。我已经有执行此操作的代码。

我最近添加了延迟加载插件,它按预期工作。但是我需要一种在延迟加载加载淡入图像后触发图像居中代码的方法。

我当前的代码基本上是这样的:

jQuery(document).ready( function($) {

// Make all lazy images ready to load themselves and listen for a custom event
$("img.lazy").lazyload({ event:"delayed-lazy-load-event", effect : "fadeIn"});

});


// Wait for the iframes and other important junk to finish loading
jQuery( window ).load( function($){

// trigger lazy loading of thumbnails.
$("img.lazy").trigger("delayed-lazy-load-event")
}

我找不到有关延迟加载的任何功能的任何信息,这些功能让我可以设置一个回调函数以在它运行淡入效果后运行。

4

2 回答 2

11

发现这个工作:

$('img.lazy').on('appear',function(){
  console.log(this)//fires this function when it appears
});
于 2015-03-27T21:06:12.137 回答
3

Entrabiter的答案实际上是在图像出现在屏幕上时触发功能,而不是在加载后触发。要在图像加载(即淡入)后运行一些代码,您需要 'load' 参数:

$('img.lazy').on('load',function(){
  console.log(this)//fires this function when it appears
});
于 2017-04-06T14:11:07.093 回答