jquery悬停鼠标 [英] jquery hover mouse out

查看:83
本文介绍了jquery悬停鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个简单的向下/向上滑动动画的链接上的鼠标。我可以将鼠标移到上面工作,但我无法弄清楚如何使用鼠标操作。

I want a simple slide down / up animation on a mouse over of a link. I can get the mouse over to work but I can't work out how to get the mouseout to do it's thing.

以下是我对悬停效果的看法:

Here's what I have for the hover effect:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<script type="text/javascript">

google.load("jquery", "1.3.2"); //load version 1.3.2 of jQuery

google.setOnLoadCallback(function() {
    jQuery(
        function($) {
            $("a.button").hover(function(){$(this).animate({"marginTop": "0px"}, "fast")   

        });
    });
});
</script>

如何在鼠标移出时将边距上移16px?

How do I get this to move the margin up 16px when mouse out?

推荐答案

jQuery中的悬停事件需要2个回调函数:一个在指针移动到项目上时,另一个当它离开时:

The hover event in jQuery needs 2 callback functions: one when the pointer moves over the item, and one when it leaves:

$(item).hover(function() { ... }, function() { ... });

您的情况:

In your case:

$("a.button").hover(
   function() {
      $(this).animate({"marginTop": "0px"}, "fast");
   },
   function() {
      $(this).animate({"marginTop": "16px"}, "fast");
   }
);

这篇关于jquery悬停鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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