我有一个变量,它从0增加到99。然后我有一个div,我想让它以相同的速度移动,但我只想定义运动的两个端点(例如向下移动,我仅定义最上方位置和最下方位置)。在主变量的值从0到99更改时,其余部分应自动插值。
所有我得到的搜索结果都与动画有关。但这不完全是动画,因为如果变量没有改变,div就不应该移动。您会如何在javascript中最好地完成这项工作?
编辑:一些模拟代码(可能存在语法错误):
所有我得到的搜索结果都与动画有关。但这不完全是动画,因为如果变量没有改变,div就不应该移动。您会如何在javascript中最好地完成这项工作?
编辑:一些模拟代码(可能存在语法错误):
<html>
<body>
<div id="increase"></div>
<div id="move"></div>
</body>
</html>
<script>
var counter =0;
var topValue =50;
var bottomValue =150;
var interpolatedValue
$('#increase').click(){
counter++;
}
$('#move').css(){
top: interpolatedValue; //this should be an interpolation between 50 and 150 based on the current counter value
}
</script>