简体   繁体   English

jQuery找到合适的缓动功能

[英]Jquery finding the right easing function

Hi all im trying to create a loading animation with html and JQuery that looks like the windows phone 7 loading animation. 大家好,我试图用html和JQuery创建加载动画,看起来像Windows Phone 7加载动画。 I have gotten this far 我已经走了这么远

http://jsfiddle.net/b6L8M/5/ http://jsfiddle.net/b6L8M/5/

But the easing function does the opposite of what i want, i want it to go fast when its on the edges and then slow down when it comes to the center. 但是缓动功能与我想要的相反,我希望它在边缘时能快速移动,而在其中心时则放慢速度。

when looking at http://jqueryui.com/demos/effect/easing.html it does not seem that there is a built-in function for that, so how would i create that function? 当查看http://jqueryui.com/demos/effect/easing.html时 ,似乎没有内置函数,那么我将如何创建该函数?

If you split-up your animation into two parts you can ease-in to the center and ease-out of the center: 如果解散动画分成两个部分,你可以ease-in市中心和ease-out中心:

function moveDot(dotItem, delay) {
    var dotItem = $(dotItem);
    dotItem.delay(delay * 200).css('left', '0%').animate({left: '50%'}, 1000, 'easeOutCirc',  function() {
        dotItem.animate({left : '100%'}, 1000, 'easeInCirc', function () {
            moveDot(dotItem[0], 0);
        });
    });
}

I also cached the $(dotItem) selection so it doesn't create a hiccup mid-animation while creating another selection (not a big chance of this happening but hey :) ). 我还缓存了$(dotItem)选择,因此它在创建另一个选择时不会造成打mid的中间动画(这种情况发生的可能性不大,但是::)。

Here is a demo: http://jsfiddle.net/b6L8M/13/ 这是一个演示: http : //jsfiddle.net/b6L8M/13/

Sometimes, you have to use more than one animate function to do what you want. 有时,您必须使用多个动画函数来执行所需的操作。

I don't know how the windows phone 7 animation looks but I tried this according on what you said : 我不知道Windows Phone 7的动画效果如何,但是我根据您所说的进行了尝试:

$(dotItem).delay(delay * 200).css('left', '0%').animate({left: '50%'}, 1000, 'easeOutQuart',  function() {
    $(this).animate({left: '100%'}, 1000, 'easeInQuart', function() {
        moveDot(dotItem, 0);
    });
});

The first one, easeOutQuart, is fast then slow down. 第一个,easeOutQuart,先快后慢。 The second is slow then accelrate. 第二个是缓慢然后加速。 I used the chaining system, but it makes the elements stop during some ms. 我使用了链接系统,但是它使元素在几毫秒内停止。 You also can use a "delay" to do so without stop. 您也可以使用“延迟”来做到这一点。

在摆弄小提琴手并使用此帖子后,使用了自定义jquery缓动功能帮助,使它能够像我想要的一样工作http://jsfiddle.net/b6L8M/24/,它与WP7加载大致相同!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM