guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

default css and display none #777

Open lekoala opened 10 years ago

lekoala commented 10 years ago

The default css allows a nice fadeIn transition. The only problem with it is that the element is still displayed as a block in the dom, which can lead to layout changes (for instances, if you have multiple input fields one after the other)

To avoid this, the .parsley-errors-list should be set to display:none. But then, no more css3 transition :-(

The solution is to use a keyframe animation, like the following:

@-webkit-keyframes parsleyFadeIn { 
  0% { opacity: 0; }
  20% { opacity: 0; }
  40% { opacity: 0.3; }
  60% { opacity: 0.5; }
  80% { opacity: 0.9; }
  100% { opacity: 1; }
}

@keyframes parsleyFadeIn {
  0% { opacity: 0; }
  20% { opacity: 0; }
  40% { opacity: 0.3; }
  60% { opacity: 0.5; }
  80% { opacity: 0.9; }
  100% { opacity: 1; }
}

.parsley-errors-list {
  margin: 2px 0 3px 0;
  padding: 0;
  list-style-type: none;
  font-size: 0.9em;
  line-height: 0.9em;
  opacity: 0;
  -moz-opacity: 0;
  -webkit-opacity: 0;

  display:none;

  color: #B82E00 !important;

  transition: all .3s ease-in;
  -o-transition: all .3s ease-in;
  -ms-transition: all .3s ease-in-;
  -moz-transition: all .3s ease-in;
  -webkit-transition: all .3s ease-in;
}

.parsley-errors-list.filled {
  opacity: 1;

  display: block;

  -webkit-animation-name: parsleyFadeIn;
  -webkit-animation-duration: .3s;
  animation-name: parsleyFadeIn;
  animation-duration: .3s;
}

What do you think?

guillaumepotier commented 10 years ago

Hi @lekoala,

Thanks for that. Do you now browser compatibility of this solution? Parsley strive to support IE7+ browsers for example.

Best

lekoala commented 10 years ago

To be honest, I haven't tested, but it should gracefuly fallback to simple show/hide if animation is not supported.