无法实现JavaScript翻转计数器

时间:2012-08-21 08:23:52

标签: javascript html counter

我想实现javascript翻转计数器。我在本文中包含了所有需要的文件和添加的代码 - http://cnanney.com/journal/code/apple-style-counter-revisited/#demo

我在页面中添加了html:

<div id="counter" class="flip-counter"></div>

并将javscript添加到我的application.js:

  var myCounter = new flipCounter("counter", {inc: 23, pace: 500});

这是我的包含文件(js和css):

      <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
      <link href="/assets/counter.css?body=1" media="all" rel="stylesheet" type="text/css" />

      <link href="/assets/jquery-ui-1.8.22.custom.css?body=1" media="all" rel="stylesheet" type="text/css" />
      <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
      <script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
      <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
      <script src="/assets/jquery-flipcounter.js?body=1" type="text/javascript"></script>
      <script src="/assets/jquery-ui-1.8.22.custom.min.js?body=1" type="text/javascript"> </script>
      <script src="/assets/application.js?body=1" type="text/javascript"></script>

我还会在这里写一下文件演示页面包含的内容:

     <!-- My flip counter script, REQUIRED -->
<script type="text/javascript" src="js/flipcounter.js"></script>
<!-- Style sheet for the counter, REQUIRED -->
<link rel="stylesheet" type="text/css" href="css/counter.css" />
<!-- NOT REQUIRED FOR COUNTER TO FUNCTION, JUST FOR DEMO PURPOSES -->
<!-- jQuery from Google CDN, NOT REQUIRED for the counter itself -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- jQueryUI from Google CDN, used only for the fancy demo controls, NOT REQUIRED for the counter itself -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<!-- Style sheet for the jQueryUI controls, NOT REQUIRED for the counter itself -->
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/vader/jquery-ui.css" />
<!-- Style sheet for the demo page, NOT REQUIRED for the counter itself -->
<link rel="stylesheet" type="text/css" href="css/demo.css" />

 这里是带有工作计数器的rar存档:https://dl.dropbox.com/u/86122402/cnanney-apple-style-flip-counter-13fd00129a41.rar

2 个答案:

答案 0 :(得分:2)

将此添加到您的application.js

$(function(){
    var myCounter = new flipCounter("counter", {inc: 23, pace: 500});
});

答案 1 :(得分:0)

一切看起来都应该有效。

尝试在自我匿名调用函数中添加JavaScript。

$(function(){
    var myCounter = new flipCounter("counter", { inc:123, pace:600});
});

还要确保所有包含的文件指向正确的位置。

将其替换为以下测试。

<script type="text/javascript" src="js/flipcounter.js"></script>
<link rel="stylesheet" type="text/css" href="css/counter.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/vader/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />