将线性动画转换为可变宽度
我有一个列表(
标记)具有可变宽度,并向左浮动......
标记),其中子元素(
我想要制作动画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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获得恒定的速度,您需要计算要行驶的距离,然后(以及给定的速度)计算达到该速度所需的时间。
例如,如果您想要 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.