当悬停在 Jquery 中时,多个图像元素全部消失。
我在仅对页面上具有相同 ID 的一个元素应用淡入淡出时遇到问题。
首先,我将图像淡入淡出至 60%,然后在悬停时,我希望它仅为图像的 100%。这部分有效,但它将效果应用于页面上的每个元素。
// Fading images
$(document).ready(function(){
$('.mainArticle img').fadeTo('slow', 0.6);
$('.mainArticle img, .articleContainer').hover(function(){
$(this).find('.mainArticle img, .articleContainer').stop(true,true).fadeTo("slow", 1.0);
},function(){
$(this).find('.mainArticle img, .articleContainer').stop(true,true).fadeTo("slow", 0.6);
});
});
我也知道如果 CSS 可以做到这一点,但要尽可能兼容。
希望你们能帮忙,
干杯,
汤姆
I'm having an issue with applying a fade to just one element on the page with the same ID.
Firstly I fade the image down to 60% and then on hover I would like it to just 100% the image. This part works but it applies the effect to every element on the page.
// Fading images
$(document).ready(function(){
$('.mainArticle img').fadeTo('slow', 0.6);
$('.mainArticle img, .articleContainer').hover(function(){
$(this).find('.mainArticle img, .articleContainer').stop(true,true).fadeTo("slow", 1.0);
},function(){
$(this).find('.mainArticle img, .articleContainer').stop(true,true).fadeTo("slow", 0.6);
});
});
Also I know this can be done if CSS but trying to be as compatible as possible.
Hope you guys can help,
Cheers,
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您再次
find()
相同的元素。$(this)
是悬停元素,因此您可以将其用于悬停处理程序:但是,我想我理解您想要做什么,并且取决于您的 HTML(如果您可以发布你的 HTML 会容易得多),你可能想将其更改为如下所示:
只有一张图像要淡入淡出: jsFiddle
具有多个图像淡入淡出: jsFiddle
You are
find()
ing the same elements again.$(this)
is the hovered element, so you can just use this for your hover handler:However, I think I understand what you are trying to do, and depending on your HTML (if you could post your HTML it would be a lot easier), you'll probably want to change it to something like this:
With only one image to fade: jsFiddle
With multiple images to fade: jsFiddle
只使用 $(this) 而不是 $(this).find('.mainArticle img, .articleContainer') 怎么样?
您正在选择与该选择器匹配的每个元素,但由于您已经将鼠标悬停在一个元素上,因此您可以仅使用 $(this) 并在那里执行更改。
How about just using $(this) instead of $(this).find('.mainArticle img, .articleContainer')?
You're selecting every element that matches that selector, but since you're already hovering one, you could just use $(this) and perform the change there.