sibanu_web/public/assets/js/components/init/scroll-to.js

45 lines
686 B
JavaScript
Raw Normal View History

2022-08-20 13:21:23 +07:00
//
// Scroll to (anchor links)
//
'use strict';
var ScrollTo = (function() {
//
// Variables
//
var $scrollTo = $('.scroll-me, [data-scroll-to], .toc-entry a');
//
// Methods
//
function scrollTo($this) {
var $el = $this.attr('href');
var offset = $this.data('scroll-to-offset') ? $this.data('scroll-to-offset') : 0;
var options = {
scrollTop: $($el).offset().top - offset
};
// Animate scroll to the selected section
$('html, body').stop(true, true).animate(options, 600);
event.preventDefault();
}
//
// Events
//
if ($scrollTo.length) {
$scrollTo.on('click', function(event) {
scrollTo($(this));
});
}
})();