1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
.size_of_img{
width:90px}
#ball {
cursor: pointer;
}
</style>
<script>
"use strict";
document.addEventListener("DOMContentLoaded", function () {
console.clear();
let conteneur = document.getElementById("conteneur");
conteneur.onmousedown = function (event) {
let shiftX = event.clientX - ball.getBoundingClientRect().left;
let shiftY = event.clientY - ball.getBoundingClientRect().top;
conteneur.style.position = 'absolute';
conteneur.style.zIndex = 1000;
moveAt(event.pageX, event.pageY);
// Déplace la balle aux cordonnées (pageX, pageY)
// Prenant en compte les changements initiaux
function moveAt(pageX, pageY) {
conteneur.style.left = pageX - shiftX + 'px';
conteneur.style.top = pageY - shiftY + 'px';
}
function onMouseMove(event) {
moveAt(event.pageX, event.pageY);
}
// déplace la balle à lévènement mousemove
document.addEventListener('mousemove', onMouseMove);
// dépose la balle, enlève les gestionnaires dévènements dont on a pas besoin
conteneur.onmouseup = function() {
document.removeEventListener('mousemove', onMouseMove);
conteneur.onmouseup = null;
};
};
conteneur.ondragstart = function() {
return false;
};
});
</script>
<div class="tooltip" id="conteneur">
<img
class="size_of_img"
id="ball"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/UIR.svg/220px-UIR.svg.png"
alt="Image 1"
/>
<span class="tooltiptext">test</span>
</div>
</body>
</html> |