【发布时间】:2023-03-23 14:55:01
【问题描述】:
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() 工作正常,但不是 3000 毫秒。
这与 500 毫秒一样快 ..!
我已多次更改 HTML、CSS 和 JS,但这不是固定的。
我该如何解决?
【问题讨论】:
-
我想以 3000 毫秒的速度移动#test div。
-
我想以 3000ms 的速度移动 #test div,但 #test div 以大约 500ms 的速度移动。
-
和3000一样
-
这是一个调试问题
-
你要求别人调试你的代码吗?
标签: javascript jquery jquery-animate duration