I have a radio button. When clicked upon, I make the page scroll to a div. That's working perfectly.
Here's the HTML for the Radio Button:
<input type="radio" id="tab" onclick="document.getElementById('mydivID').scrollIntoView();" name="tabs1" class="input">
The only thing I want more is for that scroll to be a smooth scroll. Is that possible?
document.getElementById('mydivID')
.scrollIntoView({
behavior: "smooth"
});
Let me know how that goes
here's a solution that worked for me, first get the element you want to scroll your view to then apply a smooth behavior:
const elm = document.getElementById(id)
elm.scrollIntoView({ behavior: 'smooth' })
make sure to install this polyfill (npm package):
# npm install smoothscroll-polyfill --save
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With