Files
fizzy/app/javascript/controllers/scroll_to_controller.js
T
Adrien Maston 12bc237665 Horizontal column picker
... in card perma
2025-12-17 11:34:31 +01:00

20 lines
536 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "target" ]
connect() {
this.#scrollTargetIntoView()
}
#scrollTargetIntoView() {
if(this.hasTargetTarget) {
this.element.scrollTo({
top: this.targetTarget.offsetTop - this.element.offsetHeight / 2 + this.targetTarget.offsetHeight / 2,
left: this.targetTarget.offsetLeft - this.element.offsetWidth / 2 + this.targetTarget.offsetWidth / 2,
behavior: "instant"
})
}
}
}