BBK*_*ing 3 jquery hover opacity
我有动态评论列表:
<div class="comment">
<div class="commentact">
Test1
</div>
</div>
<div class="comment">
<div class="commentact">
Test2
</div>
</div>
<div class="comment">
<div class="commentact">
Test3
</div>
</div>?
Run Code Online (Sandbox Code Playgroud)
现在我需要当用户悬停每个div class='comment'节目div class='commentact'时opacity 0.
我有这个jquery函数:(我设置div commentact默认为不透明度0.2)
$(".commentact").css('opacity','0.2');
$(document).ready(function(){
$(".comment").hover(function() {
$(".commentact").stop().animate({ opacity: 1 });
}, function() {
$(".commentact").stop().animate({ opacity: 0.2 });
});
});?
Run Code Online (Sandbox Code Playgroud)
现在当我悬停comment div显示所有commentact div不透明度为0时,有什么问题!怎么解决这个问题?演示
Rok*_*jan 11
.commentact是一个子元素,所以使用:$(this).find(".commentact")
或$(".commentact", this)
$(function(){ // DOM ready
$(".commentact").fadeTo(0, 0.2); // initial opacity
$(".comment").hover(function( e ) {
$(".commentact", this).stop().fadeTo(300, e.type=="mouseenter"? 1 : 0.2 );
});
});
Run Code Online (Sandbox Code Playgroud)