jQuery 切换图像开/关问题
对 jQuery 来说是新的,所以我很感激任何人能给我的帮助。我浏览了档案,似乎找不到我正在寻找的答案。
基本上我想要实现的功能是这样的 - 图像列表,当一个图像悬停在上面时,所有其他图像都会淡出。
我已经实现了这一点,但是,如果您将光标移动到另一个图像上,它会保持淡出状态。如果您离开换行 div,然后将光标移回其中,则淡出将起作用。我需要用户能够将光标从一张图像无缝移动到另一张图像。
这是 js-
<script type="text/javascript">
$(document).ready(function(){
$(".charity_logo img").hover(
function(){
$(this).toggleClass("trigger").next().toggleClass("trigger");
return false;
});
});
</script>
<script type="text/javascript">
var types = ["trigger"], dimmed = 1.0, threshhold = 20;
$(document).ready(function() {
$.each(types, function(index, type) {
var hover = (function() {
var timer;
return {
over: function(event) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {$("img." + type).stop().fadeTo("slow", 0.4);}, threshhold);
},
off: function(event) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {$("img." + type).stop().fadeTo("slow", dimmed);}, threshhold);
}
};
})();
$("img." + type).fadeTo(0, dimmed).hover(hover.over, hover.off);
});
});
</script>
--------------------- 这是 html--------------------- ------
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-26.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-27.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-28.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-29.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
</div><!--logo_banner-->
提前致谢!
new-ish to jQuery so I'd appreciate any help anyone could give me. I've had a look through the archives and can't seem to find an answer for what I'm looking for.
Basically the functionality I'm trying to achieve is this - a list of images, and when one image is hovered on, all the others fade out.
I have achieved this, however, if you move the cursor onto another image, it stays faded out. If you leave the wrapping div, and then move your cursor back into it, the fade out works. I need the user to be able to move their cursor from one image to the other seamlessly.
Here's the js-
<script type="text/javascript">
$(document).ready(function(){
$(".charity_logo img").hover(
function(){
$(this).toggleClass("trigger").next().toggleClass("trigger");
return false;
});
});
</script>
<script type="text/javascript">
var types = ["trigger"], dimmed = 1.0, threshhold = 20;
$(document).ready(function() {
$.each(types, function(index, type) {
var hover = (function() {
var timer;
return {
over: function(event) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {$("img." + type).stop().fadeTo("slow", 0.4);}, threshhold);
},
off: function(event) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {$("img." + type).stop().fadeTo("slow", dimmed);}, threshhold);
}
};
})();
$("img." + type).fadeTo(0, dimmed).hover(hover.over, hover.off);
});
});
</script>
---------------------and here's the html---------------------------
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-26.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-27.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-28.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
<div class="bubbleInfo charity_logo">
<a href="http://www.google.ie"><img class="trigger" alt="Charity Logo" src="<?php bloginfo('template_directory'); ?>/img/banner_logos/charity-logo-banner_01-29.jpg" /></a>
<div class="popup">
<p class="title">Charity Name</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut felis odio, aliquet vel pharetra eu.</p>
</div><!--popup-->
</div><!--charity_logo-->
</div><!--logo_banner-->
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在 css 中执行此操作,
当不将鼠标悬停在 contianer div 上时,所有内容都是完全可见的。当鼠标进入 div 时,所有 img 都设置为透明,除了您实际悬停在其上的 img
I would do this in just css
When not hovering over the contianer div, all are fully visible. When the mouse enters the div all img are set transparent, except for the img you actually hover over