如何使链接的jquery动画在彼此之间流动?

发布于 2024-09-14 18:57:11 字数 841 浏览 2 评论 0原文

查看此网站:

http://photoshop.tutorialcraft.com/

注意太阳到达顶部并然后向右。这是我的代码:

var windowWidth = $(window).width();

var width50 = (windowWidth*0.50)-220; //220 is half the width of the BG image being animated.
var width100 = (windowWidth*1);


$("#sunnmooncycle").css("backgroundPosition", "-440px 100px");.delay(2000) 

            .animate({'backgroundPosition':'('+ width50+'px '+'-400px' + ')'}, {duration:1500})
            .animate({'backgroundPosition':'('+ width100+'px '+'100px' + ')'}, {duration:1500});

如果它可以采用更多的拱形模式,而不是两个直接的动画,那就太好了。如果我在其间创建 2 个“关键帧”,在拱形所在的位置,就会出现断断续续的情况,因为 Jquery 简化了动画,而不是仅仅从一个动画流到另一个动画。

我的数学能力不够好,无法弄清楚如何做到这一点,但由于窗口的宽度是在执行之前计算的,我确信有人可能知道如何做到这一点。

那么我如何让它以拱形而不是点对点的方式制作动画呢?

Check out this site:

http://photoshop.tutorialcraft.com/

Notice the sun go to the top and then to the right. Here is my code:

var windowWidth = $(window).width();

var width50 = (windowWidth*0.50)-220; //220 is half the width of the BG image being animated.
var width100 = (windowWidth*1);


$("#sunnmooncycle").css("backgroundPosition", "-440px 100px");.delay(2000) 

            .animate({'backgroundPosition':'('+ width50+'px '+'-400px' + ')'}, {duration:1500})
            .animate({'backgroundPosition':'('+ width100+'px '+'100px' + ')'}, {duration:1500});

It would be nice if it could go in a more arching pattern, rather then two straight animations. If I create 2 "keyframes" in between, in the position where an arch would be, appears choppy, since Jquery eases animations, instead of just flowing from one to another.

I'm not good enough with math to figure out how I would do this, but since the width of the window is calculated just before execution, I'm sure someone may know how to do this.

So how do I get this to animate in an arch instead of point-to-point ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-09-21 18:57:11

查看 jQuery 的 animate 的文档。您可以通过使用值 Linear 作为调用的第三个参数来指定关闭缓动。

您可以通过这种方式设置任意数量的关键帧。

Take a look at the docs for jQuery's animate. You can simply specify the easing to be off by using the value linear as the third argument to the call.

You can set up as many keyframes as you want this way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文