延迟加载加载图像后如何触发事件? [英] How can I trigger an event after lazy load has loaded an image?

查看:105
本文介绍了延迟加载加载图像后如何触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have images that need to be absolutely positioned so that the center of the image is in the center of its parent div. I already have code that does this.

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

I recently added the Lazy Load plugin and it works as expected. But I need a way of triggering my image centering code after lazy load has loaded and faded-in the image.

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

My current code is basically this:

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")
}

我找不到有关延迟加载的任何功能的任何信息,该信息使我可以将回调函数设置为在运行fadeIn效果后运行.

I can't find any info about any feature of Lazy Load that lets me set a callback function to run after it runs the fadeIn effect.

推荐答案

发现此方法有效:

$('img.lazy').on('appear',function(){
  console.log(this)//fires this function when it appears
});

这篇关于延迟加载加载图像后如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆