开发者

css3 div 'pulse'

How does one make a div/input flash or 'pulse'? Say for example a form开发者_高级运维 field has an invalid value entered?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜