Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重复类的jQuery淡入div_Jquery_Jquery Selectors - Fatal编程技术网

重复类的jQuery淡入div

重复类的jQuery淡入div,jquery,jquery-selectors,Jquery,Jquery Selectors,我正试图做一些与这个问题中解释的非常相似的事情- 我遇到的问题是,我希望在重复类上使用淡入/淡出,而不是使用单个ID作为选择器的示例。当鼠标悬停在我的图像上时,页面上使用同一类的其他图像也会消失。以下是我得到的: HTML <div class="test"> <div class="img rounded"> <div class="post_image"> <a href="#"><

我正试图做一些与这个问题中解释的非常相似的事情-

我遇到的问题是,我希望在重复类上使用淡入/淡出,而不是使用单个ID作为选择器的示例。当鼠标悬停在我的图像上时,页面上使用同一类的其他图像也会消失。以下是我得到的:

HTML

<div class="test">
            <div class="img rounded">
                <div class="post_image"> <a href="#"><img src="http://graphics8.nytimes.com/images/2009/07/19/arts/Pool4.jpg" border="0"></a>
                </div>
            </div>
            <div class="post_body hide">
                <p>This is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fade This is a dummy text
                </p>
            </div>
        </div>


            <div class="test">
            <div class="img rounded">
                <div class="post_image"> <a href="#"><img src="http://graphics8.nytimes.com/images/2009/07/19/arts/Pool4.jpg" border="0"></a>
                </div>
            </div>
            <div class="post_body hide">
                <p>This is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fadeThis is a dummy text to fade This is a dummy text
                </p>
            </div>
        </div>

这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是一个虚拟文本

这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是FadeThat的虚拟文本这是一个虚拟文本

jQuery

<script type="text/javascript">
$(function(){
$('.test').hover(
        function(){
            $('.post_image').fadeOut(100, function(){
                $('.post_body').fadeIn(100);                         
            });
        },
        function(){
            $('.post_body').fadeOut(100, function(){
                $('.post_image').fadeIn(100);                        
            });
        }
        );


});
</script>

$(函数(){
$('.test')。悬停(
函数(){
$('.post_image').fadeOut(100,function(){
$('post_body').fadeIn(100);
});
},
函数(){
$('.post_body').fadeOut(100,function(){
$('post_image').fadeIn(100);
});
}
);
});
我很确定我在jQuery中需要一个$(this),但无法让它工作。非常感谢任何帮助

使用
$(this)
对象和
find()
函数应该更适合您:

$(function(){
    $('.test').hover(function(){
        $(this).find('.post_image').fadeOut(100,function(){
            $('.post_body').fadeIn(100);
        });
    },function(){
        $(this).find('.post_body').fadeOut(100,function(){
            $('.post_image').fadeIn(100);
        });
    });
});