Delay when animation was done

Refresh

March 2019

Views

36 time

1

I'm new in HTML, CSS, sorry if my question is not professional. I tried to find information about delay after animation but without results. Only before. My question is:

I have two buttons and div, when mouse on div - buttons should be shown - I resolved it with visibility and hover. but I need delay (when I move mouse out of div, buttons should be visible 5 sec more).

As I saw animation-delay does not resolve this issue. Please help to understand how I can do it. My code is bellow.

#deleteRow {
  width: 80px;
  height: 80px;
  background-color: #881013;
  border: none;
  background-image: url("minus.png");
  background-repeat: no-repeat;
  background-position: center;
  left: -84px;
  padding: 0px;
  margin: 0; 
  position: absolute;
  visibility:hidden;
}

#deleteCol {
  width: 80px;
  height: 80px;
  background-color: #881013;
  border: none;
  background-image: url("minus.png");
  background-repeat: no-repeat;
  background-position: center;
  top: -84px;
  right: 0px;
  padding: 0px;
  margin: 0;
  position: absolute;
  visibility:hidden;
}

.container {
  position: relative;
  display: inline-block;

}

.container:hover #deleteRow {
    visibility:visible;
    
}

.container:hover #deleteCol {
    visibility:visible;
    
    
}

3 answers

0

You also can use some JavaScript code (with jQuery library included).

$(".container").mouseenter(function(){
    $("#deleteRow,#deleteCol").css("visibility","visible");
});
$(".container").mouseout(function(){
    setTimeout(function(){
    $("#deleteRow,#deleteCol").css("visibility","hidden");
    }, 5000);
});
2

To select an element present after div as button over-here, so for that use CSS + selector, using transition-delay you can delay the transition of visibility on hover, as below,

div {
  width: 200px;
  height: 200px;
  background: red;
  margin-bottom: 20px;
}

button {
  transition: 1s ease;
  transition-delay: 5s;
}

div:hover + .btn1 {
  visibility: hidden;
}

div:hover + .btn1 + .btn2 {
  visibility: hidden;
}
<div></div>
<button class="btn1">Click - 1</button>
<button class="btn2">Click - 2</button>
0

You could use a transition on your hover properties, and put a transition-delay on it.

https://www.w3schools.com/cssref/css3_pr_transition-delay.asp