嗨我正在研究一个项目,我一直在考虑是否有可能在动画完成后启动计时器,并停止计时器onkeypress?然后将时间结果发送到另一个页面?而随着计时器我的意思是秒表所以没有计数器或其他任何东西......创建一个计时器/秒表并开始动画后
反正这里是原代码:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Exercise1</title>
<style>
.first-child {
width: 200px;
height: 200px;
background: white;
margin-top: 150px;
margin-bottom: 50px;
margin-right: 0px;
margin-left: 550px;
-webkit-animation: myfirst 1s;
animation: myfirst 1s;
}
@-webkit-keyframes myfirst {
0% {background: white;}
20% {background: white;}
40% {background: white;}
60% {background: white;}
80% {background: white;}
100% {background: red;}
}
.first-parent {
color: blue;
margin-top: 5px;
margin-bottom: 50px;
margin-left: 600px;
margin-right: 0px;
}
.second-parent {
color: red;
margin-top: 0px;
margin-bottom: 50px;
margin-left: 40px;
margin-right: 0px;
}
p {
margin-left: 640px;
}
</style>
</head>
<body>
<div class='first-child'></div>
<button class='first-parent' onclick="window.location.href='Exercise2.html' ">B</button>
<button class='second-parent' onclick="window.location.href='Exercise2.html' ">R</button>
<br />
<p>1/2</p>
<script>
document.onkeypress = function(b) {
b = b || window.event;
var charCode = b.charCode || b.keyCode,
character = String.fromCharCode(charCode);
console.log(charCode);
window.location.href="Exercise2.html";
};
document.onkeypredss = function(r) {
r = r || window.event;
var charCode = r.charCode || r.keyCode,
character = String.fromCharCode(charCode);
console.log(charCode);
window.location.href='Exercise2.html';
};
</script>
</body>
</html>
正如你可以看到,我不有任何计时器尚未...对不起但如果有任何问题只是问,我最熟悉的HTML,CSS,JavaScript和我知道一些jQuery,但如果有另一种方式来做到这一点,我也很乐意听到。先谢谢了,平安!
确定它没有工作,当我试图代码,但我觉得可能是我的浏览器或东西有问题,我使用谷歌Chrome,但我也试过在Firefox但它没有在那里工作无论是。我查看了控制台,它在Chrome和Firefox中都显示:“Uncaught ReferenceError:$未定义” – Nikki
@Nikki这意味着您没有包含jQuery。在Google上搜索如何做到这一点。基本上你必须做的是在脚本声明中添加一个链接到jQuery文件。 –
@Nikki和?它有用吗? –