을 엽니 다. 코드에 어떤 문제가 있는지 알지 못합니다.window.open 내가 함께 클릭에 새 창을 열하려고 무한 개방 루프를
전체 코드는 바이올린에 여기에 있습니다 : https://jsfiddle.net/gbPGb/196/
을 엽니 다. 코드에 어떤 문제가 있는지 알지 못합니다.window.open 내가 함께 클릭에 새 창을 열하려고 무한 개방 루프를
전체 코드는 바이올린에 여기에 있습니다 : https://jsfiddle.net/gbPGb/196/
내가 그 전문가가 또는 아직 완전히 JQuery와 이해하지만 sensely 스크립트를 이해하는 방법에 공통적으로 알고하지 않을 수 있습니다. 나는 또한 자바 스크립트를 이해하고 나는 당신의 jsfiddle를 확인했다.
에서(function(){
/*HTML5 Stop Watch by Braden Best aka B1KMusic*/
/*You can use this script anywhere and it will work*/
var cvs,ctx,W,H,mem,StopWatch,Button,mouse;
mem = {};
mouse = {x:-10,y:-10,down:false};
cvs = document.createElement('canvas');
cvs.width = W = 240;
cvs.height = H = 80;
(function appendCanvas(){
if(document.body)document.body.appendChild(cvs);
else setTimeout(appendCanvas,100);
})();
ctx = cvs.getContext('2d');
function add(o){
o.id = Math.floor(Math.random()*10000).toString(36);
for(var i in mem){
if(mem.hasOwnProperty(i) && i == o.id){
add(o);
return false;
}
}
mem[o.id] = o;
};
function remove(o){
delete mem[o.id];
};
function StopWatch(){
var started = false,
time = [[0],[0,0],[0,0],[0,0]];
this.run = function(){
var output,
h = time[0],
m = time[1],
s = time[2],
ms = time[3];
if(started){
ms[1]++;
if(ms[1]>9){ms[1]=0;ms[0]++;}
if(ms[0]>9){ms[0]=0;s[1]++;}
if(s[1]>9){s[1]=0;s[0]++;}
if(s[0]>5){s[0]=0;m[1]++;}
if(m[1]>9){m[1]=0;m[0]++;}
if(m[0]>5){m[0]=0;h[0]++;}
if(h[0]>23){ms=[0,0];s=[0,0];m=[0,0];h[0]=0;}
}
ctx.font = 'bold 36px monospace';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#000';
output = h[0]+':'+m[0]+m[1]+':'+s[0]+s[1]+'.'+ms[0]+ms[1];
ctx.fillText(output,W/2,20);
};
this.start = function(){
if (started == false) {
started = true;
window.open("https://www.w3schools.com");
}
};
this.stop = function(){
started = false;
};
this.reset = function(){
remove(this);
new StopWatch();
}
add(this);
};
function Button(x,y,t){
var x = x, y = y, w = 60, h = 30, t = t;
this.run = function(){
ctx.font = 'bold 16px monospace';
ctx.textBaseline = 'middle';
ctx.textAlign = 'center';
ctx.beginPath();//begin mouse detection
ctx.rect(x,y,w,h);
if(ctx.isPointInPath(mouse.x,mouse.y)){
ctx.fillStyle = '#eee';
if(mouse.down){
for(var i in mem){
if(mem[i].constructor.name == 'StopWatch'){
if(t == 'START')mem[i].start();
if(t == 'STOP')mem[i].stop();
if(t == 'RESET')mem[i].reset();
if(t == 'CLOSE')document.body.removeChild(cvs);
}
}
}
}else{
ctx.fillStyle = '#fff';
}
ctx.closePath();//end mouse detection
ctx.fillRect(x,y,w,h);
ctx.fillStyle = '#000';
ctx.fillText(t,x+w/2,y+h/2);
};
add(this);
};
(function init(){
new StopWatch();
new Button(0,50,'START');
new Button(60,50,'STOP');
new Button(120,50,'RESET');
new Button(180,50,'CLOSE');
})();
(function loop(){
var a
ctx.clearRect(0,0,W,H);
for(a in mem)if(mem.hasOwnProperty(a))mem[a].run();
setTimeout(loop,1000/100);
})();
cvs.onmousemove = function(e){
mouse.x = (e.pageX||e.clientX||e.offsetX) - cvs.offsetLeft;
mouse.y = (e.pageY||e.clientY||e.offsetY) - cvs.offsetTop;
return false;
};
cvs.onmousedown = cvs.onmouseup = function(e){
mouse.down = e.type == 'mousedown';
return false;
};
})();
를 실행 한 후
this.start = function(){
**if (started == false)** {
started = true;
window.open("https://www.w3schools.com");
}
};
(함수에 if 문 추가)에
this.start = function(){
started = true;
window.open("https://www.w3schools.com");
};
을 (라인 (54) 당신의 jsFiddle의 참조). 괜찮아 보였고 제공 한 주소가있는 창을 열었을뿐입니다.
새로운 바이올린 링크를 게시 해주세요. 나는 당신의 제안을 시도하고 나는 여전히 무한 루프를 얻고있다. – user2295265
https://jsfiddle.net/a_jimwel/kt8L0rge/ 여기 –
일부 버튼을 클릭 할 때이 기능을 실행해야합니다. 페이지로드가 불려지는 것 같습니다. 그래서 체인이 시작되고 끝나지 않습니다. –
먼저 이벤트를 발생시키기 위해 클릭해야하는 버튼 또는 링크를 만듭니다. '' 다음은 jquery '$ (document). (click, "# button", function() { window.open ("https : // www.w3schools.com "); }); ' –
83 행에 어떻게 든 끝낼 수 있습니까? 나는 당신이 여기에서 볼 수있는 것처럼 그것을 시도했다 : https://jsfiddle.net/gbPGb/197/ 그러나 결과는 여전히 무한 루프이다. – user2295265