I want to create a div element that disappears on hover using CSS without reappearing when moving the mouse again. While I know this can be achieved using JavaScript, I'm looking for a solution that incorporates CSS transitions for a smoother effect:
function CloseRegister() {
var regdiv = document.getElementById("register");
register.style.display = "none";
}
I have been experimenting with CSS transitions and here is what I have tried so far:
<style type="text/css">
.register
{
background-color:Purple;
transition: 2s;
-o-transition: 2s;
-webkit-transition: 2s;
-moz-transition: 2s;
}
.register:hover
{
opacity:0;
}
</style>
<div id="register" class="register" style="position:fixed; width:50%; height:50%; top:25%; left:25%;"></div>
EDIT:
I was able to resolve the issue with the help of @GolezTrol:
function CloseRegister() {
var regdiv = document.getElementById("register");
register.onmouseup = function () {
register.onmouseup = null;
register.classList.add('hovered');
setTimeout(function () { register.style.display = 'none'; }, 2000);
}
}
.register
{
background-color: Purple;
transition: 2s;
-o-transition: 2s;
-webkit-transition: 2s;
-moz-transition: 2s;
}
.register.hovered
{
background-color: transparent;
}
<div onmousedown="CloseRegister()" id="register" class="register" style="position: fixed; width: 50%; height: 50%; top: 25%; left: 25%;"></div>