views:

55

answers:

1
+1  Q: 

css3 div 'pulse'

how does one make a div/input flash or 'pulse' say for example a form field has an invalid value entered?

+2  A: 

With CSS3 something like on this page, you can add the pulsing effect to a class called error:

@-webkit-keyframes error {
  from {
    -webkit-transform: scale(1.0);
    opacity: 0.75;
  }
  50% {
    -webkit-transform: scale(1.2);
    opacity: 1.0;
  }
  to { 
    -webkit-transform: scale(1.0);
    opacity: 0.75;
  }
}

.error { 
  opacity: 0.75; 
  -webkit-animation-name: error; 
  -webkit-animation-duration: 0.5s; 
  -webkit-animation-iteration-count: 10; 
}

A YouTube demo if you're not on Safari, Chrome or another browser the above works on. The demo makes use of :hover to start the animation.

You can add the above class to invalid entries.

For example, this is very simple with the jQuery validation plugin:

$(function() {
    $("form").validate();
});​

jsFiddle example

Peter Ajtai
@peter, ah very good. I couldn't find one to make the element flash -- do you know of any examples of that?
hvgotcodes
@hvgotcodes - jQuery has some [ **simple form validation options** ](http://docs.jquery.com/Plugins/validation). Combine that with the technique above. I edited in a simplified example.
Peter Ajtai
@peter, not using jquery -- its amazing google wont show me some 'flash' enabled by webkit...
hvgotcodes