Skip to content

Instantly share code, notes, and snippets.

@mihirsam
Created December 29, 2019 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihirsam/c4023f0a3a9487a446cd32bbb407c2d6 to your computer and use it in GitHub Desktop.
Save mihirsam/c4023f0a3a9487a446cd32bbb407c2d6 to your computer and use it in GitHub Desktop.
jQuery Cycle Through Text
<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>
(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)
})
}
})()
<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