随机宽松Jquery

Random easing Jquery

本文关键字:Jquery 随机      更新时间:2023-09-26

我只想知道一种使用jQuery animate()函数执行自定义或随机宽松的方法。

我知道有一个插件有很多容易,但我想知道是否有一种方法可以添加自定义容易

所以不是线性的:

111111111111111111111111111111111111 (velocity)

或摆动:

00011111222222444422222211111000 (velocity)

我得到了这样的东西:

0011128833747733322885666111221100 (velocity)

上面的数字表示速度。我想让它变得随意一点,让它看起来更现实一点,而不是那么安排。

定义自定义函数。

jQuery.easing.custom = function( p ){
    var pow2,
		bounce = 4;
    while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
		return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
};
console.log(jQuery.easing.custom(5756836523456436));
$("button").animate({
    width: "70%",
    opacity: 0.6
}, 2000, "custom", function(){
    $( this ).after( "<div>Animation complete.</div>" );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>
    animate
</button>