Skip to content

Commit cf5e917

Browse files
committed
make settimeout consistent with setinterval
1 parent 34279a3 commit cf5e917

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

game/js/Cfunction.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ window.clearInterval = function (data) {
2424
}
2525
};
2626

27+
window.setTimeout = function(delay, fn, ctx) {
28+
var start = now();
29+
var data = Object.create(null);
30+
data.id = requestAnimationFrame(loop);
31+
32+
return data;
33+
34+
function loop() {
35+
(now() - start) >= delay
36+
? fn.call(ctx)
37+
: data.id = requestAnimationFrame(loop);
38+
}
39+
}
40+
41+
42+
window.clearTimeout = function(data) {
43+
requestAnimationFrame.cancel(data.id);
44+
}
45+
2746
var $User = (function () {
2847
const platform = navigator.platform;
2948
const userAgent = navigator.userAgent;

0 commit comments

Comments
 (0)