我试图做一个空的div与宽度和高度和背景颜色在屏幕上移动调用一个函数onclick。它不需要任何参数。但是当我点击的元素,它说:“遗漏的类型错误:未能执行的‘元素’‘动画’:?1点所需的参数,但只有0现在我失去了什么Uncaught TypeError:需要1个参数,但只存在0 ...但是我的函数没有参数?
var container = document.getElementById('container');
var box1 = document.getElementById('box1');
var containerWidth = container.clientWidth;
var box1Width = box1.clientWidth;
function animate() {
box1.style.left = '0px';
setTimeout(function() {
box1.style.transition = 'left 1000ms ease';
box1.style.left = containerWidth - box1Width + 'px';
}, 1);
}
body {
margin: 0;
}
#container {
position: relative;
height: 100vh;
width: 100vw;
background-color: aqua;
}
#box1 {
position: relative;
height: 100px;
width: 100px;
left: 0px;
background-color: yellow;
}
<div id="container">
<div id="box1" onclick="animate()"></div>
</div>
我没有在Chrome v52中遇到错误 – evolutionxbox