首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery mouseout事件

jquery mouseout事件
EN

Stack Overflow用户
提问于 2010-02-09 03:30:05
回答 1查看 965关注 0票数 1

在此代码中:

代码语言:javascript
复制
$(document).ready(function()
{
    $(".main_image .desc").show(); //Show Banner
    $(".main_image .block").animate({ opacity: 0.65 }, 1 ); 
    $(".image_thumb ul li:first").addClass('active');  
    $(".image_thumb ul li").click(function () 
    {
        var imgAlt = $(this).find('img').attr("alt");
        var imgTitle = $(this).find('a').attr("rel");
        var imgDesc = $(this).find('.block').html();
        var imgDescHeight = $(".main_image").find('.block').height();

        if ($(this).is(".active")) 
        {
        return false;
        } 
        else 
        {
            $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250, 
            function() {
                $(".main_image .block").html(imgDesc).animate({ opacity: 0.85, marginBottom:"0" }, 250 );
                $(".main_image img").attr({ src: imgTitle , alt: imgAlt});
            });
        }
    });

我改变了鼠标悬停时的点击,但我如何设置鼠标输出事件?提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-09 03:37:30

我没看到你的鼠标悬停事件处理程序。

如果您需要一个mouseover/mouseout处理程序,请使用hover(),如下所示:

代码语言:javascript
复制
$('.myelement').hover(
function() {
    // my mouseover code
},
function() {
    // my mouseout code
});

编辑:

好的,我想我明白了。要绑定“mouseout”事件(或任何事件),请执行以下操作:

代码语言:javascript
复制
$('#myelement').bind('mouseout', function() {
    // my code
});

上一次编辑:

如果你想要“停止”当前的动画,那么你需要调用stop()。考虑以下示例:

代码语言:javascript
复制
$('#box').hover(
        function() {
            $(this).stop();
            $(this).animate({height:300}, 1000);
        },
        function() {
            $(this).stop();
            $(this).animate({height:100}, 1000);
        });

#box {
    background: orange;
    width: 100px;
    height: 100px;
}

<div id='box'></box>

如果当您“鼠标移出”时动画正在进行,调用$(this).stop()将暂停动画并启动“鼠标移出”动画。如果没有“mouseout”的动画,那么只需调用$(this).stop()

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2224265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档