Created
October 7, 2023 17:07
-
-
Save bugnumber9/358dacd5d6c7d3bf381742fd80962011 to your computer and use it in GitHub Desktop.
Elementor multistep form scroll to top on next step
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function ($) { | |
| jQuery(window).on('elementor/frontend/init', function() { | |
| if (elementorModules && elementorModules.frontend) { | |
| class Custom_Steps_Top extends elementorModules.frontend.handlers.Base { | |
| getDefaultSettings() { | |
| return { | |
| selectors: { | |
| buttons: '.e-form__buttons', | |
| form: '.elementor-form', | |
| }, | |
| }; | |
| } | |
| getDefaultElements() { | |
| let selectors = this.getSettings('selectors'); | |
| return { | |
| $buttons: this.$element.find(selectors.buttons), | |
| $form: this.$element.find(selectors.form), | |
| }; | |
| } | |
| applyConditionalStep(event) { | |
| let button = jQuery(event.target); | |
| let form = button.closest('.elementor-widget-form'); | |
| jQuery('html, body').animate({ | |
| scrollTop: form.offset().top - 150 | |
| }, 400); | |
| } | |
| bindEvents() { | |
| this.elements.$buttons.on('click', this.applyConditionalStep.bind(this)); | |
| } | |
| } | |
| let Custom_Steps_Top_Handler = ($element) => { | |
| setTimeout(function() { | |
| elementorFrontend.elementsHandler.addHandler(Custom_Steps_Top, { | |
| $element, | |
| }); | |
| }, 200); | |
| }; | |
| elementorFrontend.hooks.addAction('frontend/element_ready/form.default', Custom_Steps_Top_Handler); | |
| } | |
| }); | |
| })(jQuery, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment