Created
December 29, 2019 21:23
-
-
Save mihirsam/c4023f0a3a9487a446cd32bbb407c2d6 to your computer and use it in GitHub Desktop.
jQuery Cycle Through Text
This file contains 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
<div id="cycle"> | |
<div>Meep</div> | |
<div>Moop</div> | |
<div>Beep</div> | |
<div>Peep</div> | |
<div>Poop</div> | |
<div>Loop</div> | |
<div>Neep</div> | |
</div> |
This file contains 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
(async () => { | |
const cycleContainer = $("#cycle") | |
const children = cycleContainer.children() | |
children.hide() | |
for (let i = 0; true; i++) { | |
await new Promise(res => { | |
children.eq(i % children.length) | |
.fadeIn(400) | |
.delay(1000) | |
.fadeOut(400, res) | |
}) | |
} | |
})() |
This file contains 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment