Coder Social home page Coder Social logo

Page scrolling to top on form submit about swup HOT 4 CLOSED

swup avatar swup commented on May 3, 2024
Page scrolling to top on form submit

from swup.

Comments (4)

gmrchk avatar gmrchk commented on May 3, 2024

Very nice point! This is a new feature which I actually haven't even used yet, so thank for a heads up.

I've added support for including a hash (id of the element) in the action attribute of the form, so the page will scroll to your form after sending and getting the reply.

<form action="#form" id="form" data-swup-form>

I would also suggest disabling swup's scroll on submit and enabling it after the page is reloaded, so it does not move at all when sending the form.

swup.options.scroll = false

from swup.

MikeHarrison avatar MikeHarrison commented on May 3, 2024

Thanks that's awesome! Will give it a try tomorrow. Would it be possible to elaborate a bit on the code required for your second point?

I would also suggest disabling swup's scroll on submit and enabling it after the page is reloaded, so it does not move at all when sending the form.

from swup.

gmrchk avatar gmrchk commented on May 3, 2024

Sure! The easiest way to disable scrolling for forms would be...

document.addEventListener('swup:formSubmit', event => {
    swup.options.scroll = false;
});
document.addEventListener('swup:animationInDone', event => {
    swup.options.scroll = true;
});

Didn't test it, hope there are no typos or something... but you get the idea.

from swup.

MikeHarrison avatar MikeHarrison commented on May 3, 2024

Yep that was just the ticket thank you! Slight typo, final code below in case anyone else wants to do the same:

document.addEventListener('swup:submitForm', function() {
    swup.options.scroll = false;
});
document.addEventListener('swup:animationInDone', function() {
    swup.options.scroll = true;
});

from swup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.