数学负数计算适用于 jquery 缓动旋转

math negative numbers calculation apply to a jquery easing rotate

我正在使用 jquery 缓动插件,我想将缓动 "easeInOutBounce" 应用于 div 旋转,但不像 this example 那样(其中,基于90,旋转将在0到90之间):

num = 90;
$('div').animate({borderSpacing: num},{
    step: function(now){
        if(now >= num/2){xxx = num - now;}else{xxx = now;}
        console.log(xxx);
        $(this).css('transform','rotate('+ xxx +'deg)');
    },
    duration: 1000,
    easing: 'easeInOutBounce'
},'linear');

我想做的旋转不是从 0 开始,而是将部分值转换为负数,所以动画平衡到 0:
在这种情况下,基于 90,我想要 -45 和 45 之间的动画。

我算错了,得不到我想要的结果...请帮助进行正确的数学计算,非常感谢任何帮助!

只需尝试 now = now - num/2; 而不是您的 if... 语句。

这对应于映射 now |--> now - 90/2,当 now 的域为 [0,90] 时,其范围为 [-45,45]。