JSFiddle - React, Tailwind, and code Playground
HTML
<div class="wrap"></div>
<div class="instructions">Click somewhere on the black</div>
CSS
body {
background: #ccc;
cursor: pointer;
}
.wrap {
position: absolute;
top: 100px;
left: 100px;
margin-left: -100px;
margin-top: -100px;
width: 200px;
height: 200px;
background-color: white;
background-image: url(https://www.gstatic.com/webp/gallery/4.sm.webp);
background-position: 0 0;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
border-radius: 100%;
cursor: pointer;
}
.instructions {
color: #fff;
background: #666;
position: absolute;
width: fit-content;
left: 10vh;
bottom: 10vh;
text-align: center;
-webkit-transition: opacity 200ms ease;
transition: opacity 200ms ease;
border-radius: 0.5rem;
padding: 0.25rem 0.5rem;
}
.instructions.hidden {
opacity: 0;
}
.instructions:hover {
opacity: 1;
}
JavaScript
var wrap = $('.wrap'),
instructionsVisible = true,
instructions = $('.instructions');
$(document).on('click', function (evt) {
if (instructionsVisible) {
instructions.addClass('hidden');
}
instructionsVisible = false;
wrap.animate({
top: evt.clientY || evt.offsetY || evt.pageY,
left: evt.clientX || evt.offsetX || evt.pageX
}, 350);
});