Last active
July 16, 2018 00:08
-
-
Save cup-of/2936c7e9f0df0d27adf95377ec51b2d6 to your computer and use it in GitHub Desktop.
stagger animate elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- HTML --> | |
<button>click</button> | |
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
<li>4</li> | |
<li>5</li> | |
<li>6</li> | |
</ul> | |
/* CSS */ | |
ul li { | |
position: relative; | |
opacity: 0; | |
transform: translateX(20px); | |
-webkit-transition: transform .5s ease-in-out, opacity .75s ease-in-out; | |
-moz-transition: transform .5s ease-in-out, opacity .75s ease-in-out; | |
-ms-transition: transform .5s ease-in-out, opacity .75s ease-in-out; | |
-o-transition: transform .5s ease-in-out, opacity .75s ease-in-out; | |
transition: transform .5s ease-in-out, opacity .75s ease-in-out; | |
} | |
ul.active li { | |
opacity: 1; | |
transform: translateX(0px); | |
} | |
// jquery | |
$("button").click(function(){ | |
$('ul').toggleClass('active'); | |
}); | |
let listitem = $('ul li'); | |
for (let i = 0; i < listitem.length; i++) { | |
listitem[i].style.transitionDelay = i * 100 + 'ms'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment