[英]JS mouseOver on a single repeating element (with multiple class selectors)
I'm struggling with a mouseOver effect. 我正在为mouseOver效果而苦苦挣扎。 You can see what I'm working with Here: http://jsfiddle.net/4t4nM/1/
您可以在这里看到我正在使用的工具: http : //jsfiddle.net/4t4nM/1/
Here's the HTML structure I'm using 这是我正在使用的HTML结构
<div class="row">
<div class="large-3 small-6 columns">
<div class="panel">News + Video </div>
</div>
</div>
The functionality I'm trying to build is that when you mouse over the "large-3 small-6 columns" the "panel" div in that specific cell (Not the other cells with the same class) goes through this animation: 我要构建的功能是,当您将鼠标悬停在“大3小6列”上时,该特定单元格(而不是具有相同类的其他单元格)中的“面板” div会经历以下动画:
$( function(){
$('.large-3').mouseenter( function(){
$('.panel').stop().animate({opacity:1});
}).mouseleave( function(){
$('.panel').stop().animate({opacity:0});
})
});
I am struggling to make the mouseover ONLY occur on the cell which the mouse is on & I am struggling with how to make the JS work on a div with three class selectors. 我正在努力使鼠标悬停仅发生在鼠标所在的单元格上,并且我正在努力使JS在具有三个类选择器的div上工作。
Any help is much appreciated 任何帮助深表感谢
The final application of this script will be used in this context: http://www.zoommarketing.com/jordanswonderfullandofwhat/index.html 此脚本的最终应用程序将在此上下文中使用: http : //www.zoommarketing.com/jordanswonderfullandofwhat/index.html
Your HTML is incorrect. 您的HTML不正确。 Fixed it for you here:
在这里为您修复了该问题:
<div class="row">
<div class="large-3 small 6 columns">
<img src='http://www.zoommarketing.com/jordanswonderfullandofwhat/img/smiley-1.jpg'/>
<div class="panel">Videos and News</div>
</div>
<div class="large-3 small-6 columns">
<img src='http://www.zoommarketing.com/jordanswonderfullandofwhat/img/smiley-1.jpg'/>
<div class="panel">Videos and News</div>
</div>
</div>
And here is the new Javascript to only fire on the element that is being hovered over, by using jQuery's this
selector: 这是通过使用jQuery的
this
选择器仅在被悬停的元素上触发的新Javascript:
$( function(){
$('.large-3').mouseenter( function(){
$('.panel', this).stop().animate({opacity:1});
}).mouseleave( function(){
$('.panel', this).stop().animate({opacity:0});
})
});
You are missing a closing div in the HTML. 您缺少HTML中的结束div。 But to fix the JS issue you can use $(this) to target the specific div that you're hovering over.
但是,要解决JS问题,您可以使用$(this)来定位要悬停的特定div。 Combined with the .find() function you can target the panel just for that div and show/hide.
结合.find()函数,您可以仅针对该div定位面板,并显示/隐藏。
$('.large-3').mouseenter(function () {
$(this).find('.panel').stop().animate({
opacity: 1
});
}).mouseleave(function () {
$(this).find('.panel').stop().animate({
opacity: 0
});
})
I've updated your fiddle with the fixed markup and example JS - http://jsfiddle.net/4t4nM/3/ 我已使用固定的标记和示例JS更新了您的提琴-http: //jsfiddle.net/4t4nM/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.