我的编码技巧并不是最好的,所以我需要帮助解决当前的问题。
var canvas;
jQuery(document).ready(function(){
canvas = jQuery('#myCanvas').canvaDots({
sizeDependConnections: false,
randomBounceSides: false,
dotsColor:[0,0,0,0],
linesColor:[255,255,255],
mouseReaction: true,
magnetPowerDelimiter: 5,
speed: 1.2
});
canvas.loadSpecificArray(1, arrayZ);
canvas.setSpecificArray(1, function(){});
canvas.setSpecificArrayOffsetX(10);
});
我需要以下几行才能在延迟3秒后执行
canvas.loadSpecificArray(1, arrayZ);
canvas.setSpecificArray(1, function(){});
以及延迟10秒后的以下内容。
canvas.destroytSpecificArrays(arrayZ)
我如何完成这项工作,你能指点我的方向吗?
答案 0 :(得分:3)
你可以利用一个名为setTimeout的原生JS方法。
setTimeout(function() {
canvas.destroytSpecificArrays(arrayZ)
}, 10000) //10000 ms = 10 seconds
希望有效
答案 1 :(得分:3)
您需要使用setTimeout
,其中1000 = 1秒
var canvas;
jQuery(document).ready(function(){
canvas = jQuery('#myCanvas').canvaDots({
sizeDependConnections: false,
randomBounceSides: false,
dotsColor:[0,0,0,0],
linesColor:[255,255,255],
mouseReaction: true,
magnetPowerDelimiter: 5,
speed: 1.2
});
setTimeout(()=>{
canvas.loadSpecificArray(1, arrayZ);
canvas.setSpecificArray(1, function(){});
},3000); // This function will get executed after 3 second
setTimeout(()=>{
canvas.setSpecificArrayOffsetX(10);
},10000) // This function will get executed after 10 second
});
答案 2 :(得分:3)
可以使用JavaScript setTimeout
方法进行设置。
语法很简单:
setTimeout(function() {
// your code
}, 3000) // // time in milliseconds until the above code should execute (e.g. 3000 milliseconds == 3 seconds)
在您的具体情况下,请尝试以下代码:
var canvas;
jQuery(document).ready(function(){
canvas = jQuery('#myCanvas').canvaDots({
sizeDependConnections: false,
randomBounceSides: false,
dotsColor:[0,0,0,0],
linesColor:[255,255,255],
mouseReaction: true,
magnetPowerDelimiter: 5,
speed: 1.2
});
setTimeout(function(){
canvas.loadSpecificArray(1, arrayZ);
canvas.setSpecificArray(1, function(){});
}, 3000);
canvas.setSpecificArrayOffsetX(10);
setTimeout(function(){
canvas.destroytSpecificArrays(arrayZ)
}, 10000);
答案 3 :(得分:0)
1000ms = 1s
setTimeout(function(){
console.log(1);
console.log(2);
setTimeout(function(){
console.log(3);
},10000);
},3000);