Shake a login form on error

前端 未结 9 1198
猫巷女王i
猫巷女王i 2020-12-21 02:39

I have successfully built a login form using ajax and want to add a shake effect to the form when the user enters incorrect details. I have the function in place that will f

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 03:28

    The examples above change the original position of the element.

    function shakeForm() {
        var margin = 15;
        var speed = 50;
        var times = 5;
        for( var i = 0; i < times; i++ ){  
            $( "form" ).animate( { 'margin-left': "+=" + ( margin = -margin ) + 'px' }, speed); 
            $( "form" ).animate( { 'margin-right': "+=" + ( margin = -margin ) + 'px' }, speed); 
            $( "form" ).animate( { 'margin-right': "+=" + ( margin = -margin ) + 'px' }, speed);
            $( "form" ).animate( { 'margin-left': "+=" + ( margin = -margin ) + 'px' }, speed);
        }
    }
    

    demo here http://jsfiddle.net/UW6tN/1/

提交回复
热议问题