When form is validated, how to SCROLL to the first error instead of jumping?

后端 未结 6 854
一向
一向 2021-01-30 01:34

I\'ve seen many questions with variations on this theme, but I\'m looking for the straightforward solution:

HTML form, jQuery validation, multiple fields are required. W

6条回答
  •  忘掉有多难
    2021-01-30 02:16

    just add this code to your themes javascript:

    (function($) {
    $(document).ready(function(){
        //bmo scroll to not valid
        $(".wpcf7").on('invalid.wpcf7',function(e){
            $('html, body').animate({
                    scrollTop: $(".wpcf7-not-valid").first().offset().top-30
                }, 2000);
        });
    
    });
    })(jQuery);
    

提交回复
热议问题