-->

jQuery的.hover不工作(jQuery .hover not working)

2019-06-25 16:00发布

嗨什么是错在这里我的代码:

当我将鼠标悬停在#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);

})
});
);

Answer 1:

尝试修复您的功能如下图所示,

$(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);    
    });
});


Answer 2:

只需要一点点修复

$('yourElement').hover(
   function(){
      // hover code
   }, function(){
      // unhover code 
   }
);


文章来源: jQuery .hover not working