改变数字的效果

时间:2022-08-02 18:11:19

I have a counter set like this:

我有这样一个计数器:

<ul>
    <li id="cenMill">0</li>
    <li id="decMill">0</li>
    <li id="uniMill">0</li>
    <li id="cen">3</li>
    <li id="dec">2</li>
    <li id="uni">1</li>
</ul>
    0 0 0 3 2 1

My intention is to have each number change according to a variable I give it, that is if I add +1 then just change id="uni" from 1 to 2 but if I gave it 12 then change both that are affected and so on. However I don't know how to start to do this so far this is what I have:

我的目的是让每个数字根据我给它的变量而变化,也就是说,如果我加上+1,那么就把id="uni"从1变成2,但是如果我给它12,那么就同时改变两个受影响的变量,以此类推。但是到目前为止我还不知道该怎么做这就是我的想法:

$('#uni').animate({
    marginTop: "-25px",
},200);

But this only places the 1 to the top, it doesn't make a "2" pop from underneath as the next number and the 1 is visible and I can't hide it even with display, "none" or others like it. Any help (or ideas) as to how to do this?

但这只会把1放在顶部,它不会在下一个数字下面弹出一个“2”,而1是可见的,我不能隐藏它,即使用display, none或其他类似的东西。如何做这件事有什么帮助(或想法)吗?

1 个解决方案

#1


5  

This might be similar to what you are trying to achieve: Number ticker demo.

这可能类似于您正在尝试实现的:数字代码演示。

It's a hasty copy-paste from: http://damienhowley.wordpress.com/2009/06/29/jquery-number-ticker/

这是一个仓促的复制粘贴:http://damienhowley.wordpress.com/2009/06/29/jquery-number-ticker/

Even if you can't use it as is, it should give you some pointers on how to create your own. Good luck.

即使你不能按原样使用它,它也应该给你一些关于如何创建你自己的指针。祝你好运。

#1


5  

This might be similar to what you are trying to achieve: Number ticker demo.

这可能类似于您正在尝试实现的:数字代码演示。

It's a hasty copy-paste from: http://damienhowley.wordpress.com/2009/06/29/jquery-number-ticker/

这是一个仓促的复制粘贴:http://damienhowley.wordpress.com/2009/06/29/jquery-number-ticker/

Even if you can't use it as is, it should give you some pointers on how to create your own. Good luck.

即使你不能按原样使用它,它也应该给你一些关于如何创建你自己的指针。祝你好运。