0

I'm having a little trouble calling my CSS animation with jQuery. Basically, if the value of the input is nothing, I want the form to wobble (implying something is wrong). I tried using .addClass, but it still doesn't work.

HTML

<form id="form">
     <input type="text" id="fld"/>
     <button id="btn">Get</button> 
</form>

CSS

form {
display: block;
margin: 0 auto;
width: 340px;
padding: 55px 0 0 0;
-webkit-transition: webkit-transform .75s ease-in-out;
}

.someAnimation {
-webkit-animation: errorAlert .75s ease-in-out;
}

@-webkit-keyframes errorAlert {

0%{
    -webkit-transform:translateX(-20px);
}

25%{
    -webkit-transform:translateX(20px);
}


50%{
    -webkit-transform:translateX(-20px);
}

75%{
    -webkit-transform:translateX(20px);
}

100%{
    -webkit-transform:translateX(0px);
}


}    

jQuery

$('#btn').on('click', function(){
            if($('#fld').val() == null || $('#fld').val() == ""){
                $('#form').addClass('.someAnimation');
            }
       });

2 Answers 2

4

your using .someAnimation in jquery addClass function you should use it without DOT

you should use

  $('#form').addClass('someAnimation');
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, I make that mistake a lot. Fixed it, still isn't working. It works, but moves so fast and jerky.
Is there a way to make it slower? or more smooth?
0

Replace the .someAnimation with someAnimation . Then ,

Make sure that your if() condition is true and Try using the trim() like ,

$('#btn').on('click', function(){
        if($.trim($('#fld').val()) == null || $.trim($('#fld').val()) == "")           
             alert("Condition works");
             $('#form').addClass('someAnimation');
        }
});

But not sure this works in your scenario .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.