• Resolved asiry

    (@asiry)


    Is it possible to scroll down on click or whenever a question is answered? I have built a form with hidden questions. So they will appear on the bottom. It would be nice when someone gave an answer and the next question pops, that the page scroll down to the question or just to the bottom.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @asiry

    I hope you are doing well.

    Unfortunately, it is not possible, maybe to improve the user experience you can use the pagination: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#page-break

    Best Regards
    Patrick Freitas

    Hi @asiry

    Here’s a quick and dirty javascript solution that does the trick.

    Add this javascript to any pages with the form:

    <script>
    function delay(time) {
      return new Promise(resolve => setTimeout(resolve, time));
    }
    
    const boxes = document.querySelectorAll('input');
      boxes.forEach(box => {
      box.addEventListener('click', function handleClick(event) {
        delay(500).then(() => window.scrollBy(0, 250, 'smooth'));
      });
    });
    </script>

    And add this CSS to any pages with the form (or sitewide):

    html {
        scroll-behavior: smooth;
    }
    

    Here’s how it looks in action: http://recordit.co/v0fD41z2l7.gif

    Hope this helped

    Thread Starter asiry

    (@asiry)

    Dear @aakash8

    I added the code, but it doesn’t work.
    Can you check if I did it right? (https://caretix.nl/gezondheidstest/)

    @wpmudevsupport12 Thank you for your fast response.

    @asiry

    I’m seeing an error that the const/variable boxes is already being used elsewhere on you site. Try this instead:

    <script>
    function delay(time) {
      return new Promise(resolve => setTimeout(resolve, time));
    }
    
    const forminator_boxes = document.querySelectorAll('input');
      forminator_boxes.forEach(box => {
      box.addEventListener('click', function handleClick(event) {
        delay(500).then(() => window.scrollBy(0, 250, 'smooth'));
      });
    });
    </script>
    Thread Starter asiry

    (@asiry)

    @aakash8

    I am grateful for your time. Thank you.

    It is still not working.

    @asiry

    No problem.
    The error is gone now, I think we just need to run the script after page load now.

    Try:

    <script>
    window.onload = function () {
        function delay(time) {
            return new Promise(resolve => setTimeout(resolve, time));
        }
    
        const forminator_boxes = document.querySelectorAll('input');
        forminator_boxes.forEach(box => {
            box.addEventListener('click', function handleClick(event) {
                delay(500).then(() => window.scrollBy(0, 250, 'smooth'));
            });
        });
    };
    </script>

    Have to sign off for now, hopefully this does the trick! Otherwise someone will get back to you. Good luck.

    Thread Starter asiry

    (@asiry)

    @aakash8

    Now it works 🙂

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Scroll down on click’ is closed to new replies.