Sha256: 1526ec84f6460a199ab2f080f1971616a5a30ed4dcd4329f95d09908b1ab96ac
Contents?: true
Size: 782 Bytes
Versions: 13
Compression:
Stored size: 782 Bytes
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { return [ "button", "container" ] } connect() { this.scrollElement.addEventListener("scroll", this.load.bind(this)) this.load() // Initial load } disconnect() { this.scrollElement.removeEventListener("scroll", this.load.bind(this)) } load() { if (this.hasButtonTarget) { let top = this.buttonTarget.getBoundingClientRect().top if (top < window.innerHeight + 500) { this.buttonTarget.click() this.buttonTarget.remove() } } } get scrollElement() { if (this.hasContainerTarget) { return this.containerTarget } else { return document.getElementById("main") } } }
Version data entries
13 entries across 13 versions & 1 rubygems