jQuery悬停仅在第二次悬停时有效

jQuery悬停仅在第二次悬停时有效,jquery,html,css,function,Jquery,Html,Css,Function,我是jQuery新手,我的.hover函数有问题。当我第一次将鼠标悬停在图像上时,动画确实工作,但当我再次将鼠标悬停在图像上时,动画工作正常。谢谢你的帮助。您可以在zacknoblauch.com上查看一个实例,以下是我的代码: html: } } jQuery: $(function(){ $(".home_post_box").hover(function(){ $(".home_post_text", this).stop().animate({t

我是jQuery新手,我的.hover函数有问题。当我第一次将鼠标悬停在图像上时,动画确实工作,但当我再次将鼠标悬停在图像上时,动画工作正常。谢谢你的帮助。您可以在zacknoblauch.com上查看一个实例,以下是我的代码:

html:

}

}

jQuery:

 $(function(){
        $(".home_post_box").hover(function(){
            $(".home_post_text", this).stop().animate({top:"0px"},{queue:false,duration:1000});
    },

        function() {
            $(".home_post_text", this).stop().animate({top:"200px"},{queue:false,duration:1000});
        });
    });

使用最近距离进行Div选择

closest( selector  )
    .closest( selector )
    .closest( selector [, context] )
    .closest( jQuery object )
    .closest( element )
closest( selectors [ , context ]  )
.最近(选择器[,上下文])
$(this).closest(“div.first-div”).find(“div.inside-div”)

摆脱
可见性:隐藏和添加
顶部:200px到.home\u post\u文本

.home_post_text {
background-color: #50D07D;
width: 320px;
height: 200px;
padding: 0;
position: absolute;
bottom: 0;
left: 0;
color: #fff;
z-index: 10;
text-decoration: none;    
//visibility: hidden;
top: 200px; }

试试看:

您需要为css中的
top
声明一个值。。。现在它默认为
auto
——你不能从
auto
0px
删除我的帖子,因为你的答案比我的快30秒,而且更简洁!
 $(function(){
        $(".home_post_box").hover(function(){
            $(".home_post_text", this).stop().animate({top:"0px"},{queue:false,duration:1000});
    },

        function() {
            $(".home_post_text", this).stop().animate({top:"200px"},{queue:false,duration:1000});
        });
    });
closest( selector  )
    .closest( selector )
    .closest( selector [, context] )
    .closest( jQuery object )
    .closest( element )
closest( selectors [ , context ]  )
.home_post_text {
background-color: #50D07D;
width: 320px;
height: 200px;
padding: 0;
position: absolute;
bottom: 0;
left: 0;
color: #fff;
z-index: 10;
text-decoration: none;    
//visibility: hidden;
top: 200px; }