首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Jquery中停止动画效果( stop方法)

如何在Jquery中停止动画效果( stop方法)
EN

Stack Overflow用户
提问于 2013-04-07 16:49:26
回答 1查看 80关注 0票数 0

我是Jquery的新手,我正在尝试制作动画,但我不知道如何停止动画。

我有3张图片,它们的高度或宽度在3个锚标签中不相等,它们堆叠在一个div中。

我写了一个脚本,当你鼠标输入()一个图片时,图片的宽度应该增加20px,当你鼠标离开()时,宽度应该达到预览的宽度。

我设法做到了这一点,但是当我用鼠标快速浏览图像时,开始变大和变小,布局变得混乱。

我找到了一些插件,可以做我需要的,但它们都使用相同宽度和高度的图像。

如果有人能帮上忙,我将不胜感激。

以下是代码http://jsfiddle.net/ClaudiuTicu/9kTft/2/的链接

代码语言:javascript
复制
 var original_w;
$('.getBigger').on('mouseenter', function () {
    original_w = $(this).find('img').width(); //add the width of thye image to the parent
    original_h = $(this).find('img').height(); //add the height to the parent

    if ($(this).find('img').is(':animated')) { }
    else {
        if ($(this).attr('style')) { } //has the style attribut
        else {
            $(this).css({
                'width': original_w,
                'height': original_h
            });
        } //dosen't have the style attribut
    }

    if ($(this).find('img').width() == original_w) {
        $(this).find('img').animate({
            'width': original_w + 20
        }).addClass('hovered');
    } //if the image width is equal with the parent's width
    else {

    }


}).on('mouseleave', function () {
    if ($(this).find('img').width() != original_w) {
        $(this).find('img').animate({
            'width': original_w
        }).removeClass('hovered');
    }
    console.log(original_w);
}); //end mouse leave
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-07 16:55:45

在所有.animate()实例之前使用.stop(true,true) -它强制动画进入其最终状态,并移除所有排队的动画。

示例:

代码语言:javascript
复制
$(this).find('img').stop(true,true).animate(...);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15860561

复制
相关文章

相似问题

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