admin管理员组文章数量:1405407
I have an app created with laravel livewire where I'm loading a livewire ponent with multiple nested ponents that display one at a time depending upon a status variable. When each nested ponent is displayed the page is scrolled to the bottom. I'd like the default scroll be to the top. At the top of a nested ponent I've tried:
x-data x-init="window.scrollTo(0, 0)"
I've also tried scrolling the page to the top using a click event prior to hiding ponent 1 and displaying ponent 2. This would be to ensure the page is scrolled to the top prior to displaying ponent 2.
x-data x-on:click.document="window.scrollTo(0, 0)"
Neither approach is working. Thanks in advance.
I have an app created with laravel livewire where I'm loading a livewire ponent with multiple nested ponents that display one at a time depending upon a status variable. When each nested ponent is displayed the page is scrolled to the bottom. I'd like the default scroll be to the top. At the top of a nested ponent I've tried:
x-data x-init="window.scrollTo(0, 0)"
I've also tried scrolling the page to the top using a click event prior to hiding ponent 1 and displaying ponent 2. This would be to ensure the page is scrolled to the top prior to displaying ponent 2.
x-data x-on:click.document="window.scrollTo(0, 0)"
Neither approach is working. Thanks in advance.
Share Improve this question asked Feb 10, 2021 at 5:26 JustinJustin 2877 silver badges20 bronze badges1 Answer
Reset to default 3I realized it wasn't the window that I needed to scroll it was a <div>
within the window. Hence, using solution 2, I scroll to the top of the div after the action of clicking a button to display the next ponent (and hide the current). When the next ponent displays the containing div is scrolled to the top.
I'd still rather not need to implement this workaround but not sure how else to prevent the div from being scrolled to the bottom when the next ponent is shown.
本文标签: javascriptscroll to top of pagelivewire componentalpine jsStack Overflow
版权声明:本文标题:javascript - scroll to top of page - livewire component - alpine js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744893145a2630903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论