Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
besty-boy authored Apr 10, 2024
0 parents commit 6c97032
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function moveButton(event) {
let button = document.getElementById('myButton');
let mouseX = event.clientX;
let mouseY = event.clientY;
let buttonX = button.offsetLeft + button.offsetWidth / 2;
let buttonY = button.offsetTop + button.offsetHeight / 2;

let distance = Math.sqrt(Math.pow(mouseX - buttonX, 2) + Math.pow(mouseY - buttonY, 2));
let threshold = 100;
if (distance < threshold) {
let newLeft = Math.random() * (window.innerWidth - button.offsetWidth);
let newTop = Math.random() * (window.innerHeight - button.offsetHeight);


newLeft = Math.max(newLeft, 4);
newLeft = Math.min(newLeft, window.innerWidth - button.offsetWidth - 4);
newTop = Math.max(newTop, 4);
newTop = Math.min(newTop, window.innerHeight - button.offsetHeight - 4);

button.style.left = newLeft + 'px';
button.style.top = newTop + 'px';
}
}
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="fr">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="DESCRIPTION DE LA PAGE">
<link rel="stylesheet" href="/assets/css/style.css">
<link rel="icon" href="/assets/img/pp.jpg">
<title>Auto-Button</title>
</head>

<body onmousemove="moveButton(event)">
<!-- Bouton -->
<button id="myButton">Cliquez-moi</button>

<script src="https://kit.fontawesome.com/c0bd8faac8.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="assets/js/script.js"></script>
</body>

</html>

0 comments on commit 6c97032

Please sign in to comment.