css3 - CSS animations, slide in on 'block' and out on 'none' -


i'm building using css slide animation have text slide in when text display set "block", wondering how go doing reverse (sliding out) when set "none"? possible slide in , slide out css animations, or have use javascript?

hope makes sense! let me know if have questions!

jsfiddle of give better idea https://jsfiddle.net/qjwql236/

thanks!

and code below:

document.getelementbyid("in-button").onclick = function(){  	document.getelementbyid("text-container").style.display = "block";  }    document.getelementbyid("out-button").onclick = function(){  	document.getelementbyid("text-container").style.display = "none";  }
#text-container{    height: 30px;    width:300px;    color: white;    background-color: blue;    float:left;    display:none;        position: relative;    left: -300px;    animation: slide 0.5sforwards;    -webkit-animation: slide 0.5s forwards;  }    @-webkit-keyframes slide {    100% {      left: 0;    }  }  @keyframes slide {    100% {      left: 0;    }  }    #in-button{    float:left;   }     #out-button{    float:left;   }
<button id="in-button">  make div slide in  </button>    <button id="out-button">  make div slide out?  </button>    <br>  <br>    <div id="text-container">    text in div.  </div>

in case. it's easier use transition animation. how works.

everytime button click. changes value of left property.

<button id="in-button"> make div slide in </button>  <button id="out-button"> make div slide out? </button>  <br> <br>  <div id="text-container">   text in div. </div> 

css

#text-container{   height: 30px;   width:300px;   color: white;   background-color: blue;   float:left;   position: relative;   left: -400px;   transition: 0.3s linear }  #in-button, #out-button{   float:left; } 

js

var tc = document.getelementbyid('text-container');  document.getelementbyid("in-button").onclick = function(){     tc.style.left = '0'; }  document.getelementbyid("out-button").onclick = function(){     tc.style.left = '-400px'; } 

working fiddle: https://jsfiddle.net/qjwql236/1/


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -