4 разноцветных квадрата должны двигаться и перемещаться в серый квадрат, меняя его цвет.
<style>
div[id$='Box']{
width: 100px;
height: 100px;
margin-bottom: 5em;
border: 2px solid black;
cursor: pointer;
}
#yellowBox{
background: yellow;
}
#greenBox{
background: green;
}
#blueBox{
background: blue;
}
#redBox{
background: red;
}
#gray{
width: 300px;
height: 300px;
background: gray;
margin: auto;
position: absolute;
left: 50%;
top: 200px;
}
</style>
</head>
<body>
<div id="gray"></div>
<div id="yellowBox"></div>
<div id="greenBox"></div>
<div id="blueBox"></div>
<div id="redBox"></div>
<script>
let boxs = document.querySelectorAll("div[id$='Box']");
for(box of boxs){
box.onmousedown = function(e){
console.log("click")
box = e.correntTarget;
box.style.position = "absolute";
box.style.zIndex = 1000;
function moveAt(event){
let x = event.clientX-50;
let y = event.clientY-50;
box.style.top = y+"px"
box.style.left = x+"px"
}
document.addEventListener('mousemove', moveAt);
document.onmouseup = function(){
document.removeEventListener('mousemove', moveAt);
}
let box_top = box.getBoundingClientRect().top;
let box_left = box.getBoundingClientRect().left;
let box_right = box.getBoundingClientRect().right
let box_bottom = box.getBoundingClientRect().bottom
let gray_top = gray.getBoundingClientRect().top;
let gray_left = gray.getBoundingClientRect().left;
let gray_right = gray.getBoundingClientRect().right;
let gray_bottom = gray.getBoundingClientRect().bottom;
if(box_left>gray_left && box_right < gray_right && box_top > gray_top && box_bottom < gray_bottom){
gray.style.background = box.style.background;
box.style.visibility = "hidden";
}
}
}
lesson_11.php:53 Uncaught TypeError: Cannot read property 'style' of undefined
at HTMLDivElement.box.onmousedown (lesson_11.php:53)
Выдает такую ошибку, что то там со стилями не так.