将线性动画转换为可变宽度

发布于 2024-12-19 21:50:40 字数 682 浏览 3 评论 0原文

我有一个列表(

    标记),其中子元素(
  • 标记)具有可变宽度,并向左浮动......

我想要制作动画marginLeft 到特定点

动画希望对于任何宽度都具有恒定的速度。

首先,我使用以下代码捕获 ul 的长度

ul_length=parseFloat($("#developments ul").css("width"))+
          parseFloat($("#developments ul").css("paddingLeft"))+
          parseFloat($("#developments ul").css("paddingRight"));

现在如何我可以修改上面的代码以获得constant_speed吗任何宽度?

$scrollhandler=$("#developments ul").animate({
        marginLeft: -1*(ul_width+li_padding)
        }, {
        duration: ul_length,
        easing: "linear"
    });

I have a list (<ul> tag) which children elements (<li> tag) has variable width, and floating left....

I want to animate marginLeft to a specific point

The animation would like to have constant speed, for any width..

First of all, I catch the length of the ul with the following code

ul_length=parseFloat($("#developments ul").css("width"))+
          parseFloat($("#developments ul").css("paddingLeft"))+
          parseFloat($("#developments ul").css("paddingRight"));

Now how can i modify the above code to have constant_speed for any width?

$scrollhandler=$("#developments ul").animate({
        marginLeft: -1*(ul_width+li_padding)
        }, {
        duration: ul_length,
        easing: "linear"
    });

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

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

发布评论

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

评论(1

喵星人汪星人 2024-12-26 21:50:40

为了获得恒定的速度,您需要计算要行驶的距离,然后(以及给定的速度)计算达到该速度所需的时间。

例如,如果您想要 10 像素/秒的速度,并且需要覆盖 50 像素(计算得出),则需要为动画指定 5 秒的长度。

In order to have constant speed, you want to calculate the distance you're going to cover, and then by that, (and the given speed), calculate the time it would take to reach that speed.

For instance, if you'd like a speed of 10px/sec, and you have 50px to cover (calculated), you'll need to give the animation a 5 second length.

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