Odometer.js 在 Meteor 中不起作用?

Odometer.js Does Not Work within Meteor?

我正在尝试使用 odometer.js. But it seems like I can't get past the first step - getting the odometer javascript code to run properly inside Meteor. When that code executes, it's supposed to find all DOM elements with the .odometer class and perform some DOM element manipulation based on the stylesheet theme you've selected in order to prepare the DOM for animated number manipulation. Simple example here.

在我的 Meteor 模板中获取反应性数字以进行动画处理

对于那些不熟悉该库的人,如果您在 jsFiddle 运行后对其进行检查,您就会明白我所说的 DOM 操作是什么意思。该脚本将一个简单的 <div class="odometer"></div> 转换为嵌套的层次结构:

样式表在 Meteor 中正确加载——如果我在 <head> 标签内四处寻找,我可以在 application.css 内看到 classes。但是脚本没有执行或没有正确执行,因为 DOM 永远不会更改为数字操作所需的特殊 class 层次结构。

没有 JS 错误警告被打印到控制台。有没有人能够让里程表在 Meteor 中工作?谢谢!

如果您想使用任何库,您需要将脚本放在 /client/lib 目录中,以便它首先加载。

然而,我为odometer写了一个名为d4nyll:odometeor, which has all the functionalities plus it allows you to use templating. A demo can be found at odometeor.meteor.com的包,它会每4秒随机更改一次数字。

使用:

  1. 运行 meteor add d4nyll:odometeor
  2. 要么在模板中包含 {{> odometeor 888}},要么使用 Odometeor.create()
  3. 直接使用 $('.odometeor').html([--YOUR-NEW-NUMBER]);
  4. 更改值

Full documentation