当图像实际出现在屏幕上时,如何让jQuery调用事件处理程序? [英] How can I get jQuery to call an event handler when an image actually appears on-screen?

查看:74
本文介绍了当图像实际出现在屏幕上时,如何让jQuery调用事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向下滚动并看到图片时,如何使用jQuery触发JavaScript函数的回调?我希望延迟加载某些图像,直到它们实际出现在屏幕上...理想情况下,我可以执行以下操作:

  $('#img#')。look_on(){... 

所以没有我们认为这个JQuery Event Plugin可以满足您的需要:

解决方案

元素'查看'事件插件


我创建了一个事件,当元素滚动到视口。


同样,LazyLoad插件似乎有一个视口选择器用于JQuqery: 这里


How can I use jQuery to trigger a callback of a JavaScript function when I scroll down and see a picture? I wish to delay loading certain images until they actually appear on-screen... Ideally, I'd be able to do something like:

$('#img#').look_on() { ...

So no images are loaded apart from those I have seen.

解决方案

I think this JQuery Event Plugin does what you need:

Element 'in view' Event Plugin

I've created an event that will trigger when the element is scrolled in to the viewport.

also, the LazyLoad Plugin seems to have a "viewport" selector for JQuqery: Here.

这篇关于当图像实际出现在屏幕上时,如何让jQuery调用事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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