* @private
*/
_events() {
- const handleLinkClick = (e) => {
- // Follow the link it does not point to an anchor.
- if (!$(e.currentTarget).is('a[href^="#"]')) return;
+ this.$element.on('click.zf.smoothScroll', this._handleLinkClick)
+ this.$element.on('click.zf.smoothScroll', 'a[href^="#"]', this._handleLinkClick);
+ }
- const arrival = e.currentTarget.getAttribute('href');
+ /**
+ * Handle the given event to smoothly scroll to the anchor pointed by the event target.
+ * @param {*} e - event
+ * @function
+ * @private
+ */
+ _handleLinkClick(e) {
+ // Follow the link it does not point to an anchor.
+ if (!$(e.currentTarget).is('a[href^="#"]')) return;
- this._inTransition = true;
+ const arrival = e.currentTarget.getAttribute('href');
- SmoothScroll.scrollToLoc(arrival, this.options, () => {
- this._inTransition = false;
- });
+ this._inTransition = true;
- e.preventDefault();
- };
+ SmoothScroll.scrollToLoc(arrival, this.options, () => {
+ this._inTransition = false;
+ });
- this.$element.on('click.zf.smoothScroll', handleLinkClick)
- this.$element.on('click.zf.smoothScroll', 'a[href^="#"]', handleLinkClick);
- }
+ e.preventDefault();
+ };
/**
* Function to scroll to a given location on the page.