<!-- I'm keeping the src empty to emulate -->
<div class="cont">
<div>
<p>
To emulate the annoying behavior I'm preloading the image and make make it visible when the <strong>mouse</strong> move closer to the button.
</p>
<p>
<i>Para emular el comportamiento molesto estoy precargando la imagen y haciéndola visible cuando el <strong>mouse</strong> se mueve cerca del botón.</i>
</p>
<figure>
<img alt="" id="my-image"/>
</figure>
<div class="cont-button">
<button id="detect-intention">
Try to click this / Intenta clickear esto
</button>
</div>
</div>
</div>
body {
font-family: sans-serif;
text-align: center;
}
img {
display: block;
margin: auto;
}
figure {
border: 1px #eee solid;
align-items: center;
display: flex;
justify-content: center;
min-height: 30px;
padding: 15px;
position: relative;
}
figure::before {
content: 'Something would be loading here… / Algo estaría cargando aquí…';
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
figure.loaded::before {
display: none;
}
.cont {
align-items: center;
display: flex;
justify-content: center;
padding: 15px;
}
.cont-button {
align-items: center;
background: #fafafa;
display: flex;
justify-content: center;
margin: auto;
padding: 50px;
width: auto;
}
button {
background: #eee;
border: 0;
border-radius: 3px;
box-shadow: 2px 2px 8px 2px rgba(0, 0, 0, .15);
cursor: pointer;
padding: 15px 28px;
}
const preloadImg = new Image();
preloadImg.src = 'https://placekitten.com/200/100';
document.getElementById('detect-intention').onmousemove = function() {
document.getElementById('my-image').src = 'https://placekitten.com/200/100';
document.querySelector('figure').classList.add('loaded');
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.