0

我在页面的头部有这个来加载pace.js带有加载栏动画的文件。

<head>
    <script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script data-pace-options='{ "startOnPageLoad": false }' src="pace/pace.min.js"></script>
    <link href="pace/pace-theme-loading-bar.css" type="text/css" rel="stylesheet" />
    <!--- I tried using this for my 2. question, but I couldn't find out how to use the ".selector" part -->
    <script data-pace-options='{ "elements": { "selectors": [".selector"] }, "startOnPageLoad": false }' src="pace/pace.min.js"></script>
</head>

而且在体内

<body>
  <?php
  // some PHP code

  ?>
  <script type = "text/javascript" >
       $(document).ready(function() {
            // some oder jQuery functions and other code

            $.getScript(scriptPath, function(data, textStatus, jqxhr) {
                 // some other code

            });

       });
  </script>
</body>
  1. 我怎样才能在$(document).ready(function() {});部分之后直接获得速度?

  2. 是否可以只在$.getScript部分调用速度动画?

我搜索了很多,无法得到我的问题的明确答案。

更新

如果我把它Pace.start()直接放在后面$(document).ready(function() {

但它只在 Chrome 和资源管理器中可用,有人知道为什么它在 Firefox 中不起作用吗?

<body>
  <?php
  // some PHP code

  ?>
  <script type = "text/javascript" >
       $(document).ready(function() {
            Pace.start() // to start the pace animation 
            // some oder jQuery functions and other code

            $.getScript(scriptPath, function(data, textStatus, jqxhr) {
                 // some other code

            });

       });
  </script>
</body>

只有在 Firefox 的控制台中,当我加载

<link href="pace/pace-theme-loading-bar.css" type="text/css" rel="stylesheet" />

> Expected ':' but found 'none'.  Declaration dropped.pace-theme-loading-bar.css:2:25
Expected ':' but found 'none'.  Declaration dropped.pace-theme-loading-bar.css:3:17
Expected ':' but found 'none'.  Declaration dropped.pace-theme-loading-bar.css:5:22
Expected ':' but found 'none'.  Declaration dropped.pace-theme-loading-bar.css:6:19
Expected ':' but found 'none'.  Declaration dropped.pace-theme-loading-bar.css:7:14
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:9:21
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:10:18
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:11:17
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:12:16
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:13:13
Expected ':' but found '10px'.  Declaration dropped.pace-theme-loading-bar.css:15:24
Expected ':' but found '10px'.  Declaration dropped.pace-theme-loading-bar.css:16:21
Expected ':' but found '10px'.  Declaration dropped.pace-theme-loading-bar.css:17:16
Expected ':' but found 'padding-box'.  Declaration dropped.pace-theme-loading-bar.css:19:26
Expected ':' but found 'padding'.  Declaration dropped.pace-theme-loading-bar.css:20:23
Expected ':' but found 'padding-box'.  Declaration dropped.pace-theme-loading-bar.css:21:18
Expected ':' but found '2000'.  Declaration dropped.pace-theme-loading-bar.css:23:10
Expected ':' but found 'fixed'.  Declaration dropped.pace-theme-loading-bar.css:24:11
Expected ':' but found 'auto'.  Declaration dropped.pace-theme-loading-bar.css:25:9
Expected ':' but found '12px'.  Declaration dropped.pace-theme-loading-bar.css:26:6
Expected ':' but found '0'.  Declaration dropped.pace-theme-loading-bar.css:27:7
Expected ':' but found '0'.  Declaration dropped.pace-theme-loading-bar.css:28:8
Expected ':' but found '0'.  Declaration dropped.pace-theme-loading-bar.css:29:9
Expected ':' but found '200px'.  Declaration dropped.pace-theme-loading-bar.css:30:8
Expected ':' but found '50px'.  Declaration dropped.pace-theme-loading-bar.css:31:9
Expected ':' but found 'hidden'.  Declaration dropped.pace-theme-loading-bar.css:32:11
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:36:21
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:37:18
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:38:17
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:39:16
Expected ':' but found 'border-box'.  Declaration dropped.pace-theme-loading-bar.css:40:13
Expected ':' but found '2px'.  Declaration dropped.pace-theme-loading-bar.css:42:24
Expected ':' but found '2px'.  Declaration dropped.pace-theme-loading-bar.css:43:21
Expected ':' but found '2px'.  Declaration dropped.pace-theme-loading-bar.css:44:16
Expected ':' but found 'padding-box'.  Declaration dropped.pace-theme-loading-bar.css:46:26
Expected ':' but found 'padding'.  Declaration dropped.pace-theme-loading-bar.css:47:23
Expected ':' but found 'padding-box'.  Declaration dropped.pace-theme-loading-bar.css:48:18
Expected ':' but found 'translate3d('.  Declaration dropped.pace-theme-loading-bar.css:50:20
Expected ':' but found 'translate3d('.  Declaration dropped.pace-theme-loading-bar.css:51:12
Expected ':' but found 'block'.  Declaration dropped.pace-theme-loading-bar.css:53:10
Expected ':' but found 'absolute'.  Declaration dropped.pace-theme-loading-bar.css:54:11
Expected ':' but found '100%'.  Declaration dropped.pace-theme-loading-bar.css:55:8
Expected ':' but found '-7px'.  Declaration dropped.pace-theme-loading-bar.css:56:15
Expected ':' but found '93%'.  Declaration dropped.pace-theme-loading-bar.css:57:8
Expected ':' but found '7px'.  Declaration dropped.pace-theme-loading-bar.css:58:6
Expected ':' but found '14px'.  Declaration dropped.pace-theme-loading-bar.css:59:9
Expected ':' but found '12px'.  Declaration dropped.pace-theme-loading-bar.css:60:12
Expected ':' but found '#\32 9d'.  Declaration dropped.pace-theme-loading-bar.css:61:13
Expected ':' but found '#\32 9d'.  Declaration dropped.pace-theme-loading-bar.css:62:8
Expected ':' but found '60px'.  Declaration dropped.pace-theme-loading-bar.css:63:14
Expected ':' but found 'bold'.  Declaration dropped.pace-theme-loading-bar.css:64:14
Expected ':' but found 'Helvetica'.  Declaration dropped.pace-theme-loading-bar.css:65:14
Expected ':' but found '120px'.  Declaration dropped.pace-theme-loading-bar.css:67:21
Expected ':' but found '120px'.  Declaration dropped.pace-theme-loading-bar.css:68:17
Expected ':' but found '120px'.  Declaration dropped.pace-theme-loading-bar.css:69:13
Expected ':' but found 'attr('.  Declaration dropped.pace-theme-loading-bar.css:73:10
Expected ':' but found 'inline-block'.  Declaration dropped.pace-theme-loading-bar.css:74:10
Expected ':' but found 'fixed'.  Declaration dropped.pace-theme-loading-bar.css:75:11
Expected ':' but found '45px'.  Declaration dropped.pace-theme-loading-bar.css:76:8
Expected ':' but found 'right'.  Declaration dropped.pace-theme-loading-bar.css:77:13
Expected ':' but found '0'.  Declaration dropped.pace-theme-loading-bar.css:78:8
Expected ':' but found '16px'.  Declaration dropped.pace-theme-loading-bar.css:79:16
Expected ':' but found '4px'.  Declaration dropped.pace-theme-loading-bar.css:80:6
Expected identifier or string for value in attribute selector but found '0%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:83:40
Expected identifier or string for value in attribute selector but found '1%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:84:40
Expected identifier or string for value in attribute selector but found '2%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:85:40
Expected identifier or string for value in attribute selector but found '3%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:86:40
Expected identifier or string for value in attribute selector but found '4%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:87:40
Expected identifier or string for value in attribute selector but found '5%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:88:40
Expected identifier or string for value in attribute selector but found '6%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:89:40
Expected identifier or string for value in attribute selector but found '7%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:90:40
Expected identifier or string for value in attribute selector but found '8%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:91:40
Expected identifier or string for value in attribute selector but found '9%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:92:40
Expected identifier or string for value in attribute selector but found '10%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:93:40
Expected identifier or string for value in attribute selector but found '11%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:94:40
Expected identifier or string for value in attribute selector but found '12%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:95:40
Expected identifier or string for value in attribute selector but found '13%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:96:40
Expected identifier or string for value in attribute selector but found '14%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:97:40
Expected identifier or string for value in attribute selector but found '15%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:98:40
Expected identifier or string for value in attribute selector but found '16%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:99:40
Expected identifier or string for value in attribute selector but found '17%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:100:40
Expected identifier or string for value in attribute selector but found '18%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:101:40
Expected identifier or string for value in attribute selector but found '19%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:102:40
Expected identifier or string for value in attribute selector but found '20%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:103:40
Expected identifier or string for value in attribute selector but found '21%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:104:40
Expected identifier or string for value in attribute selector but found '22%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:105:40
Expected identifier or string for value in attribute selector but found '23%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:106:40
Expected identifier or string for value in attribute selector but found '24%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:107:40
Expected identifier or string for value in attribute selector but found '25%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:108:40
Expected identifier or string for value in attribute selector but found '26%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:109:40
Expected identifier or string for value in attribute selector but found '27%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:110:40
Expected identifier or string for value in attribute selector but found '28%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:111:40
Expected identifier or string for value in attribute selector but found '29%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:112:40
Expected identifier or string for value in attribute selector but found '30%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:113:40
Expected identifier or string for value in attribute selector but found '31%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:114:40
Expected identifier or string for value in attribute selector but found '32%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:115:40
Expected identifier or string for value in attribute selector but found '33%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:116:40
Expected identifier or string for value in attribute selector but found '34%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:117:40
Expected identifier or string for value in attribute selector but found '35%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:118:40
Expected identifier or string for value in attribute selector but found '36%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:119:40
Expected identifier or string for value in attribute selector but found '37%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:120:40
Expected identifier or string for value in attribute selector but found '38%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:121:40
Expected identifier or string for value in attribute selector but found '39%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:122:40
Expected identifier or string for value in attribute selector but found '40%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:123:40
Expected identifier or string for value in attribute selector but found '41%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:124:40
Expected identifier or string for value in attribute selector but found '42%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:125:40
Expected identifier or string for value in attribute selector but found '43%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:126:40
Expected identifier or string for value in attribute selector but found '44%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:127:40
Expected identifier or string for value in attribute selector but found '45%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:128:40
Expected identifier or string for value in attribute selector but found '46%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:129:40
Expected identifier or string for value in attribute selector but found '47%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:130:40
Expected identifier or string for value in attribute selector but found '48%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:131:40
Expected identifier or string for value in attribute selector but found '49%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:132:40
Expected identifier or string for value in attribute selector but found '50%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:133:40
Expected identifier or string for value in attribute selector but found '51%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:134:40
Expected identifier or string for value in attribute selector but found '52%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:135:40
Expected identifier or string for value in attribute selector but found '53%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:136:40
Expected identifier or string for value in attribute selector but found '54%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:137:40
Expected identifier or string for value in attribute selector but found '55%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:138:40
Expected identifier or string for value in attribute selector but found '56%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:139:40
Expected identifier or string for value in attribute selector but found '57%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:140:40
Expected identifier or string for value in attribute selector but found '58%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:141:40
Expected identifier or string for value in attribute selector but found '59%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:142:40
Expected identifier or string for value in attribute selector but found '60%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:143:40
Expected identifier or string for value in attribute selector but found '61%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:144:40
Expected identifier or string for value in attribute selector but found '62%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:145:40
Expected identifier or string for value in attribute selector but found '63%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:146:40
Expected identifier or string for value in attribute selector but found '64%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:147:40
Expected identifier or string for value in attribute selector but found '65%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:148:40
Expected identifier or string for value in attribute selector but found '66%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:149:40
Expected identifier or string for value in attribute selector but found '67%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:150:40
Expected identifier or string for value in attribute selector but found '68%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:151:40
Expected identifier or string for value in attribute selector but found '69%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:152:40
Expected identifier or string for value in attribute selector but found '70%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:153:40
Expected identifier or string for value in attribute selector but found '71%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:154:40
Expected identifier or string for value in attribute selector but found '72%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:155:40
Expected identifier or string for value in attribute selector but found '73%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:156:40
Expected identifier or string for value in attribute selector but found '74%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:157:40
Expected identifier or string for value in attribute selector but found '75%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:158:40
Expected identifier or string for value in attribute selector but found '76%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:159:40
Expected identifier or string for value in attribute selector but found '77%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:160:40
Expected identifier or string for value in attribute selector but found '78%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:161:40
Expected identifier or string for value in attribute selector but found '79%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:162:40
Expected identifier or string for value in attribute selector but found '80%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:163:40
Expected identifier or string for value in attribute selector but found '81%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:164:40
Expected identifier or string for value in attribute selector but found '82%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:165:40
Expected identifier or string for value in attribute selector but found '83%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:166:40
Expected identifier or string for value in attribute selector but found '84%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:167:40
Expected identifier or string for value in attribute selector but found '85%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:168:40
Expected identifier or string for value in attribute selector but found '86%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:169:40
Expected identifier or string for value in attribute selector but found '87%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:170:40
Expected identifier or string for value in attribute selector but found '88%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:171:40
Expected identifier or string for value in attribute selector but found '89%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:172:40
Expected identifier or string for value in attribute selector but found '90%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:173:40
Expected identifier or string for value in attribute selector but found '91%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:174:40
Expected identifier or string for value in attribute selector but found '92%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:175:40
Expected identifier or string for value in attribute selector but found '93%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:176:40
Expected identifier or string for value in attribute selector but found '94%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:177:40
Expected identifier or string for value in attribute selector but found '95%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:178:40
Expected identifier or string for value in attribute selector but found '96%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:179:40
Expected identifier or string for value in attribute selector but found '97%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:180:40
Expected identifier or string for value in attribute selector but found '98%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:181:40
Expected identifier or string for value in attribute selector but found '99%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:182:40
Expected identifier or string for value in attribute selector but found '100%'.  Ruleset ignored due to bad selector.pace-theme-loading-bar.css:183:40
Expected ':' but found 'absolute'.  Declaration dropped.pace-theme-loading-bar.css:187:11
Expected ':' but found '100%'.  Declaration dropped.pace-theme-loading-bar.css:188:8
Expected ':' but found '28px'.  Declaration dropped.pace-theme-loading-bar.css:189:9
Expected ':' but found '2001'.  Declaration dropped.pace-theme-loading-bar.css:190:10
Expected ':' but found 'inset'.  Declaration dropped.pace-theme-loading-bar.css:191:13
Expected ':' but found '10px'.  Declaration dropped.pace-theme-loading-bar.css:192:16
Expected ':' but found 'none'.  Declaration dropped.
4

1 回答 1

0

您可以使用 jquery 像这样加载外部 js 文件。将代码放置在您希望加载的任何位置 -

$.getScript("my_lovely_script.js", function(){
    // whatever you want to happen after the script has been loaded goes here.
});
于 2016-08-13T14:15:59.330 回答