0

Below Playground I have code with the button to scroll at the top of the page and conditionally render the button when user scrolled down. Now if I remove the custom render thing then button works as expected but when I add the custom css for conditional rendering then button stopped working,

Playground

On above playground when you scroll down, a button will appear at the bottom left but when you click on it won't scroll at the top.

1

add this in goToTop function remove everything else

  this.template.querySelector('.test').scrollTop=0;

and in the html class assign class name test like

<div class='test' style="overflow: auto; position: fixed; top: 0; left: 0; right: 0; bottom: 0; " onscroll={onScroll}> 
  • it is working as expected in the playground but in real time I am getting this error Uncaught TypeError: this.template.querySelectorAll(...)[0].scrollTo is not a function, could you please suggest on it – gs650x Nov 11 at 8:09
  • i have updated my answer @gs650x – Kushal Chauhan Nov 12 at 6:54
  • Thank you, but we cannot add scroll behavior with this. – gs650x Nov 12 at 6:56
  • can you share your code.i just deployed this its working fine for me – Kushal Chauhan Nov 12 at 7:01
  • It works fine but how to add scroll behavior with the same? – gs650x Nov 12 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.