Created
March 23, 2023 20:56
-
-
Save jch/799f8b1fcc3764b6707af8bb31eb5e98 to your computer and use it in GitHub Desktop.
Stimulus slideshow controller, because I'm too stupid to do modulo math
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
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