jQuery 缓动在我的 animate() 调用中不起作用

2023-12-28

我有 4 个圆形按钮,位于中心区域在我的页面上 http://goo.gl/yacZly。将鼠标悬停其中一个会使其尺寸增大,但我想为这些按钮的增大和缩小运动添加一些缓动/弹跳效果。

但是由于某种原因,缓动部分不起作用。我确实将缓动插件添加到我的页面中:

<script src='js/jquery.easing.1.3.js'></script> 

以下是按钮行为的代码:

$('.egg_button')
    .on('mouseenter', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: -5,
            width: "+=10",
            height: "+=10",
            backgroundSize: "30px",
            specialEasing: {
                width: "easeOutBounce",
                height: "easeOutBounce"
            }
        }, 'fast');
    })
    .on('mouseleave', function(){
        var div = $(this);
        div.stop(true, true).animate({ 
            margin: 0,
            width: "-=10",
            height: "-=10",
            backgroundSize: "22px",
            specialEasing: {
                width: "easeOutBounce",
                height: "easeOutBounce"
            }
        }, 'fast');
    })

你把easing:说明符位置错误。应该是这样的:

$(document).ready(function(){
    $(".egg_button").hover(
        function() {
            var div = $(this);
            div.stop(true, true).animate({
                margin: -5,
                width: "+=10",
                height: "+=10",
                backgroundSize: "30px",         // Instead of here ..
            }, {
                duration: 500, 
                queue:false, 
                easing: 'easeOutBounce'         // .. put it here
            });
        },
        function() {
            var div = $(this);
            div.stop(true, true).animate({
                margin: 0,
                width: "-=10",
                height: "-=10",
                backgroundSize: "22px",        // Instead of here ..
            }, {
                duration: 500, 
                queue:false, 
                easing: 'easeOutBounce'        // .. put it here
            });
        }
    );
});

这是我为您准备的 jsFiddle 示例,您可以根据自己的喜好调整设置:

DEMO http://jsfiddle.net/rtk3p98v/

别忘了看看这个宽松备忘单 http://easings.net/这可以让您更好地了解每个缓动函数的具体作用。祝你好运!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jQuery 缓动在我的 animate() 调用中不起作用 的相关文章

随机推荐