<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="background-wrapper">
<img class="background" src="https://picsum.photos/300/100?1"/>
</div>
</body>
</html>
let getImg = document.querySelector('.background');
let backgroundArrayImg = [
'https://picsum.photos/300/100?1', 'https://picsum.photos/300/100?2', 'https://picsum.photos/300/100?3'
];
let count = 1;
getImg.addEventListener('click', () => {
if(count === backgroundArrayImg.length){
count = 0;
}
else{
getImg.src = backgroundArrayImg[count];
count++;
}
})
var ball = document.querySelector('.value1');
ball.onmousedown = function(e) {
var coords = getCoords(ball);
var shiftX = e.pageX - coords.left;
var shiftY = e.pageY - coords.top;
ball.style.position = 'absolute';
document.body.appendChild(ball);
moveAt(e);
ball.style.zIndex = 1000;
function moveAt(e) {
ball.style.left = e.pageX - shiftX + 'px';
ball.style.top = e.pageY - shiftY + 'px';
}
document.onmousemove = function(e) {
moveAt(e);
};
ball.onmouseup = function() {
document.onmousemove = null;
ball.onmouseup = null;
};
}
ball.ondragstart = function() {
return false;
};
function getCoords(elem) {
var box = elem.getBoundingClientRect();
return {
top: box.top + pageYOffset,
left: box.left + pageXOffset
};
}
let clearBtn = document.querySelector('.clear-btn');
clearBtn.addEventListener('click', () => {
resultElement.textContent = '';
tNumber.value = undefined;
aNumber.value = undefined;
rNumber.value = undefined;
})