JS:
var time, key, speed, noteTime;
function readTextFile(file) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if(rawFile.readyState === 4) {
if(rawFile.status === 200 || rawFile.status == 0) {
var allText = rawFile.responseText;
var occ = occurrences(allText, "\n", "false");
var string = allText.split("\n");
for (i = 0; i < occ; i++) {
time = string[i].split("{time:");
time = time[1].split(",key:");
key = string[i].split(",key:");
key = key[1].split(",speed:");
speed = string[i].split(",speed:");
speed = speed[1].split("}");
speed = speed[0];
noteTime = time[0] - 3000;
if(noteTime < 0) {
noteTime = 0;
}
console.log(noteTime);
console.log(speed);
setTimeout(function(){
$("#test").animate({
left: "+=100"
}, speed);
}, noteTime);
}
}
}
}
rawFile.send(null);
}
readTextFile("mercury.myr");
HTML:
<div style="height:50px; width:50px; background-color: black; position: relative;" id="test"></div>
mercury.myr:
{time:7000,key:32,speed:3000}\n
..我认为这是正确的代码,但不是。
jQuery animate()正在运行,但它不是3000ms
这快到500ms ..!
我已多次更改HTML,CSS和JS,但这不是固定的
我该如何解决?
答案 0 :(得分:1)
setTimeout(function(){
$("#test").animate({
left: "+=100"
}, speed);
}, noteTime);
将speed
替换为3000