Mastering Element Scrolling in Lightning Web Components - Techdicer

PHOTO EMBED

Mon Oct 07 2024 02:22:52 GMT+0000 (Coordinated Universal Time)

Saved by @WayneChung

import { LightningElement } from 'lwc';

export default class ScrollToElement extends LightningElement {
    handleScrollClick() {
        console.log('Button clicked');
        const topDiv = this.template.querySelector('[data-id="redDiv"]');
        if (topDiv) {
            topDiv.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
        }
    }
}
content_copyCOPY

https://techdicer.com/mastering-element-scrolling-in-lightning-web-components/