Skip to content

Instantly share code, notes, and snippets.

@jch
Created March 23, 2023 20:56
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 jch/799f8b1fcc3764b6707af8bb31eb5e98 to your computer and use it in GitHub Desktop.
Save jch/799f8b1fcc3764b6707af8bb31eb5e98 to your computer and use it in GitHub Desktop.
Stimulus slideshow controller, because I'm too stupid to do modulo math
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "slide" ]
initialize() {
this.index = 1
}
next(e) {
e.preventDefault()
this.slideTargets.forEach(c => { c.classList.add('hidden') })
this.slideTargets[(this.index++%this.slideTargets.length)].classList.remove('hidden')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment