加载检测特定图像然后做一些事情...... [英] Detect specific image is loaded then do something...

查看:103
本文介绍了加载检测特定图像然后做一些事情......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我慢慢地了解JS / Jquery,我需要有关如何检测特定图像何时可见的帮助/指导,因此我可以删除不同元素上的类。很简单我确定...只是想了解逻辑。

I'm getting my head around JS/Jquery slowly and I need help/guidance on how to detect when a "specific" image is "visible", so I can then remove a class on a different element. Simple I'm sure...just trying to understand the logic.

JS。

$('.my-big-hero').find('my-image-here.jpg:visible').removeClass('class-i-want-removed');

这可能是一个简单的(以及错误的方式)来显示这个,但它是为了让你了解我正在努力实现的目标。我已经尝试了各种方法来写这个而不是赢。

This is probably a simple (and wrong way) to display this, but it was to give you an idea of what I'm trying to achieve. I've tried various ways to write this and not winning.

感谢你能给予的任何帮助......先谢谢你。

Appreciate any help you can give....thank you in advanced.

推荐答案

您可以使用 .is(可见) toggleClass 函数,这样:

You can use the .is("visible") and the toggleClass functions, this way:

$('.my-big-hero').find('my-image-here.jpg').toggleClass('class-i-want-removed', !$(this).is(':visible'));

然后该元素将具有类 class-i-want-removed 如果它不可见,则一旦可见,该类将被删除。

Then the element will have the class class-i-want-removed if it is not visible, and the class will be removed once it is visible.

这篇关于加载检测特定图像然后做一些事情......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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