jQuery .hover无法正常工作 [英] jQuery .hover not working

查看:91
本文介绍了jQuery .hover无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的代码出了什么问题:

Hi What is wrong with my code here:

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

When I hover over #open #pull_down_content should be moving down the page from the header and when I move away from #open it should move back up. But when I test the code as soon as the page loads #pull_down_content moves down the screen before I even hover over it.

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

})
});
);


推荐答案

尝试修改下面的函数,

Try fixing your function like below,

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

这篇关于jQuery .hover无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆