css - How to create div that automatically slides in and out with CSS3 -
i want create div automatic slides in when calling webpage , ability close x , if not press x automatic closes after 5 sec.
so lets say: top of webpage slide in , div 200px width , 200px height.
how can create css3 transitions?
follow below code slider div using css3:
first add below css in html:
<style> .slider { background: #000; color: #fff; height: 20px; position: relative; padding: 30px; -moz-animation-name: dropslider; -moz-animation-iteration-count: 1; -moz-animation-timing-function: ease-out; -moz-animation-duration: 1s; -webkit-animation-name: dopslider; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease-out; -webkit-animation-duration: 1s; animation-name: dropslider; animation-iteration-count: 1; animation-timing-function: ease-out; animation-duration: 1s; } @-moz-keyframes dropslider { 0% { -moz-transform: translatey(-250px); } 100$ { -mox-transform: translatey(0); } } @-webkit-keyframes dropslider { 0% { -webkit-transform: translatey(-250px); } 100% { -webkit-transform: translatey(0); } } @keyframes dropslider { 0% { transform: translatey(-250px); } 100% { transform: translatey(0); } } #divslider.close { opacity:0; } button { position: absolute; top: 0px; right: 0px; } </style>
now, add below code in body part:
<div align='center'> <div id='divslider' class='slider' style='height:200px; width:200px; border:solid;'> <button type='button' onclick='closeme();'>x</button> <h1>slider div</h1> </div> </div>
then add below script after end of body:
<script> settimeout(function() { document.getelementbyid('divslider').classname = 'close'; }, 5000); function closeme() { document.getelementbyid('divslider').classname = 'close'; } </script>
finally, html ready execute....
i'm sure this'll solve out issue , if it's don't forget mark answer... (^_^)
thanks...
settimeout(function() { document.getelementbyid('divslider').classname = 'close'; }, 5000); function closeme() { document.getelementbyid('divslider').classname = 'close'; }
.slider { background: #000; color: #fff; height: 20px; position: relative; padding: 30px; -moz-animation-name: dropslider; -moz-animation-iteration-count: 1; -moz-animation-timing-function: ease-out; -moz-animation-duration: 1s; -webkit-animation-name: dopslider; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease-out; -webkit-animation-duration: 1s; animation-name: dropslider; animation-iteration-count: 1; animation-timing-function: ease-out; animation-duration: 1s; } @-moz-keyframes dropslider { 0% { -moz-transform: translatey(-250px); } 100$ { -mox-transform: translatey(0); } } @-webkit-keyframes dropslider { 0% { -webkit-transform: translatey(-250px); } 100% { -webkit-transform: translatey(0); } } @keyframes dropslider { 0% { transform: translatey(-250px); } 100% { transform: translatey(0); } } #divslider.close { opacity: 0; } button { position: absolute; top: 0px; right: 0px; }
<div align='center'> <div id='divslider' class='slider' style='height:200px; width:200px; border:solid;'> <button type='button' onclick='closeme();'>x</button> <h1>slider div</h1> </div> </div>
Comments
Post a Comment