Please tell me how to rewrite this code in the jQuery widget?
let scrollToTopBtn = document.getElementById('back_top');
let rootElement = document.documentElement;
function scrollToTop() {
rootElement.scrollTo({
top: 0,
behavior: 'smooth'
});
}
scrollToTopBtn.addEventListener('click', scrollToTop);
By example:
$.widget( "backToTop", {
//...
});
You really do not need JS for that. You can use the CSS scroll-behavior
property and a normal link with the href
set to #
.
Nor do you need jQuery if it has to be a button using JS
As for your question, I’m not sure I know what widget you are referring to.
https://api.jqueryui.com/jQuery.widget/
system
Closed
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.