How to add delay to Display: block

0

I'm creating a website, and I'd like it to have a "button" with the WhatsApp icon, and by hovering over that button, it would expand and show the number I put there. Currently the code looks like this:

HTML:

<div id="whatsapp"></div>    
<div id="whatsnumber">(99)99999-9999</div>

CSS:

#whatsapp{
position:fixed;
width:40px;
height:40px;
margin-top:calc(50vh - 55px);
background:url(img/whatsapp.png);
background-color: #25D366;
background-position: center center;
background-size: cover;

}
#whatsapp:hover{
width:50px;
transition-duration: 0.2s;
}

#whatsnumber{
display:none;
font-size:2rem;
position: fixed;
margin-top:calc(50vh - 55px);
margin-left: 40px;
width:max-width;
height:40px;
background: #25D366;
line-height: 40px;
border-right: 10px solid #25D366;
color: white;
}

#whatsapp:hover ~ #whatsnumber{
display: block;
}

#whatsnumber:hover{
display: block;
}

#whatsapp:not(hover){
width:40px;
transition-duration: 0.2s;
}

The idea is that there are two DIVs, one (#whatsapp) that when the mouse over will expand, and another (#whatsnumber) that when you mouse over it should wait a second and then appear. p>

I tried to use the transition-delay to make the "display: block" take effect after a second, but it is not working.

How to solve?

    
asked by anonymous 29.09.2017 / 14:25

2 answers

2

Here's an alternative.

div {
  clear: both;
}

.icon {
  position: absolute;
  top: 0px;
  left: 0px;  
  height: 32px;
  width: 32px;
  background-repeat: no-repeat;
  background-size: calc(100% - 4px);
  background-position: center;
}

.social {
  position: relative;
  float: left;
  width: 32px;
  padding-left: 32px;
  box-sizing: border-box;
  overflow: hidden;  
  line-height: 32px;
  border-radius: 5px;
  box-shadow: 0px 0px 5px black;
  white-space: nowrap;
  transition: width 0.5s linear;
  margin: 3px 0px;
}

.social:hover {
  width: 150px;
}

.icon-whatsapp {
  background-image: url('https://image.flaticon.com/icons/svg/220/220236.svg');
}

.icon-skype {
  background-image: url('https://image.flaticon.com/icons/svg/220/220235.svg');
}

.icon-tweet {
  background-image: url('https://image.flaticon.com/icons/svg/220/220233.svg');
}

.icon-facebook {
  background-image: url('https://image.flaticon.com/icons/svg/220/220200.svg');
}
<div class="social">
  <div class="icon icon-whatsapp"></div>
  (99)99999-9999
</div>
<div class="social">
  <div class="icon icon-skype"></div>
  (99)99999-9999
</div>
<div class="social">
  <div class="icon icon-facebook"></div>
  (99)99999-9999
</div>
<div class="social">
  <div class="icon icon-tweet"></div>
  (99)99999-9999
</div>
    
29.09.2017 / 14:50
0

Can not add transition to events: display and visibility .

The explanation is:

  

Both visibility: hidden; and the display: none; do not respond to event   handlers, while opacity allows event handlers to be   called.

Then you can arrive at the expected result using opacity and transition ( transition ) with 1 second:

#whatsapp{
position:fixed;
width:40px;
height:40px;
margin-top:calc(50vh - 55px);
background:url(img/whatsapp.png);
background-color: #25D366;
background-position: center center;
background-size: cover;
transition: all 1s;
}
#whatsapp:hover{
width:50px;
}

#whatsnumber{
opacity:0;
font-size:2rem;
position: fixed;
margin-top:calc(50vh - 55px);
margin-left: 40px;
width:max-width;
height:40px;
background: #25D366;
line-height: 40px;
border-right: 10px solid #25D366;
color: white;
transition: all 1s;
}

#whatsapp:hover ~ #whatsnumber{
opacity: 1;
}

#whatsnumber:hover{
opacity: 1;
}

#whatsapp:not(hover){
width:40px;
}
<div id="whatsapp"></div>    
<div id="whatsnumber">(99)99999-9999</div>

More information on this question: transition does not work in Javascript

    
29.09.2017 / 14:38