I wanted a Button similar to the Dynamic Page Scroll Button but I wanted it to scroll to a specific element. So I adjusted the plugin slightly:
/* START OF PLUGIN CODE FOR Dynamic Page Scroll Button */
(function() {
var scrollToNewsletterBtn = jQuery('<button>', {
class: 'btn btn-default',
id: 'tb_scroll_btn_' + 'Scroll To Newsletter'.replace(/\s/g, "_").toLowerCase(),
text: 'Newsletter abonnieren',
});
var parentDiv = jQuery('<div>', {
class: 'tb-page-scroll-to-component',
css: { position: 'fixed', bottom: '6rem', right: '12px', display: 'grid', gap: '1rem' }
});
jQuery('.tb-page-scroll-to-component').length === 0 && jQuery('body').append(parentDiv);
jQuery('#tb_scroll_btn_' + 'Scroll To Newsletter'.replace(/\s/g, "_").toLowerCase()).length === 0 && jQuery('.tb-page-scroll-to-component').append(scrollToNewsletterBtn);
jQuery(window).scroll(function() {
let scrollTop = jQuery(this).scrollTop();
let elementOffset = jQuery('#newsletter-iframe').offset().top;
jQuery(scrollToNewsletterBtn).toggle(scrollTop < elementOffset - 100);
});
jQuery(scrollToNewsletterBtn).on('click', function() {
jQuery('html, body').animate({
scrollTop: jQuery('#newsletter-iframe').offset().top
}, 750);
});
})();
/* END OF PLUGIN CODE FOR Dynamic Page Scroll Button */
#newsletter-iframe is my element. change this to the element you want to address in these two places:
let elementOffset = jQuery('#newsletter-iframe').offset().top;
scrollTop: jQuery('#newsletter-iframe').offset().top
This is where you adjust the Button label:
text: 'Newsletter abonnieren'