Form doesn't move up on submit

后端 未结 3 877
粉色の甜心
粉色の甜心 2021-01-24 05:59

I\'m trying to move the form up a few pixels and this doesn\'t work. I don\'t know why.

The function is being called when I submit (I have tested it with an alert()), bu

相关标签:
3条回答
  • 2021-01-24 06:18

    You are using css top without any position properties. Try using position absolute or relative

    $(document).ready(function () {
                $("#formulario").submit(function (event) {
                    $(this).css({
                        top: '-50px',
                        position: 'relative'
                    });
                });
            });
    

    If you do not wish to change the position property, you can modify the margin-top property like

    $(document).ready(function () {
                    $("#formulario").submit(function (event) {
                        $(this).css({
                            marginTop: '-50px'
                        });
                    });
                });
    

    Finally, note that when a form submits, the page reloads so you will most likely only see this change temporarily. If you return false, the page will not reload(although this may not be what you want)

    $(document).ready(function () {
                        $("#formulario").submit(function (event) {
                            $(this).css({
                                marginTop: '-50px'
                            });
                            return false;
                        });
                    });
    
    0 讨论(0)
  • 2021-01-24 06:21

    Can you try adding position: relative; also

            $("#formulario").submit(function (event) {
                $(this).css({
                    position: "relative",
                    top: "-50px"
                });
    
            });
    
    0 讨论(0)
  • 2021-01-24 06:29

    If you want it to work with .animate() try this:

    $(document).ready(function () {
        $("#formulario").submit(function (event) {
            event.preventDefault();
            $(this).css('position', 'relative')
                .animate({top: '-50px'}, 5000, function () {
                    // Animation complete.
                })
        });
    });
    
    0 讨论(0)
提交回复
热议问题