0

So I would like to make an overlay with a black background and with a text that slides down from top to center(using the @-webkit-keyframes with the from,to method containing translate() css events) when clicking on a font awesome youtube icon and then make it slide from center to top when clicking on a font awesome checkbox(using the onclick="myFunction()" html argument) that is under the overlay text, I suceeded at making the part where I click on the font awesome youtube icon and the black overlay pops up and the text slides down with a nice transition but i can't make it slide up when clicking the font awesome checkbox.

I tried using this article to make the center to top transition, slide out transition to put in my javascript code that matches my onClick="myFunction" argument: Set the webkit-keyframes from/to parameter with JavaScript . Here is my code:

HTML:

<div class="youtubebutton">
<a class="fab fa-youtube" id="youtube" onclick="ytbclick()"></a>
</div>
<div id="overlayytb">
  <div id="text">This link is coming soon.<div>
  <a class="fas fa-check-square" onclick="okbutton()"></a>
</div>

Javascript:

<script>

function ytbclick() {
document.getElementById("overlayytb").style.display = "block";
}

function okbutton() {

  // document.getElementById("text").style.animationDirection = "reverse";
  // document.getElementById("text").style.Display = "block";
  var cssAnimation = document.createElement('style');
  cssAnimation.type = 'text/css';
  var rules = document.createTextNode('#newtext > #text {'+'animation-name: slidedown2;'+
 ' animation-direction: reverse;'+
  'animation-fill-mode: forwards;'+
  'animation-duration: .5s;'+'}'+'-@webkit-keyframes slidedown2'+'{'+'from{transform: translate(-50%,-50%);}'+'to{transform: translate(-50%,-467%);}'+'}');
  cssAnimation.appendChild(rules);
  document.getElementsByTagName("head")[0].appendChild(cssAnimation);
}
</script>

CSS for the slide in animation:

#overlayytb {

  position: fixed; 
  display: none; 
  width: 100%; 
  height: 100%; 
  top: 0; 
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5);  /*Black background with opacity */
  z-index: 2; 
  cursor: pointer; 

}

#text{
  position: absolute;
  font-family: 'Montserrat', sans-serif;
  top: 50%;
  left: 50%;
  font-size: 50px;
  letter-spacing: 0px;
  color: white;
  transform: translate(-50%,-50%);
  /*-ms-transform: translate(-50%,-50%);*/
  animation-name: slidedown;
  animation-delay: 0s;
  animation-fill-mode: forwards;
  animation-duration: .5s;
  animation-direction: normal;
}

@-webkit-keyframes slidedown
{
    0%
    {
        transform: translate(-50%,-467%);
    }
    100%
    {
        top:50%;
        transform: translate(-50%,-50%);
    }
}
3
  • Is there a particular reason why you want to use CSS3 animations instead of CSS3 transitions? developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/… Commented Jun 2, 2019 at 1:18
  • No, there isn't any particular reason that I use css3 animations instead of css3 transitions. Although Do you think it would be practical to use it in my case, or even easier for the effect im looking for? Commented Jun 2, 2019 at 8:09
  • When you are going from one specific state to a second, then transitions are the best option. Commented Jun 2, 2019 at 20:19

1 Answer 1

0

I Figured it out, I used jQuery animate function for the slide in transition with the margin and opacity arguments, then for the fade out option i used javascript to make the opacity to 0 when clicked on the button with the click function. Thanks Kravimir :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.