3

嗨我的代码有什么问题:

当我将鼠标悬停在#open 上时,#pull_down_content 应该从页眉向下移动,当我离开 #open 时,它应该向上移动。但是,当我在页面加载后立即测试代码时,#pull_down_content 会在我将鼠标悬停在它上面之前向下移动屏幕。

$(function() {

//Open on hover 
$('#open').hover((function(){
    $('#pull_down_content').animate({'top':'-0px'},1000);
})

//Close when not hovered
(function(){
    $('#pull_down_content').animate({'top':'-340px'},1000);

})
});
);
4

2 回答 2

15

尝试如下修复您的功能,

$(function() {        
    $('#open').hover(function(){ //Open on hover 
        $('#pull_down_content').animate({'top':'-0px'},1000);
    },    
    function(){ //Close when not hovered
        $('#pull_down_content').animate({'top':'-340px'},1000);    
    });
});
于 2012-06-21T16:03:28.133 回答
1

只需要一点修复

$('yourElement').hover(
   function(){
      // hover code
   }, function(){
      // unhover code 
   }
);
于 2012-06-21T16:05:48.407 回答