LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Animated Text Input [beta]

CSS
.field {
  display: flex;
  flex-wrap: wrap;
}

.input_label {
  font-size: 14px;
  line-height: 16px;
  pointer-events: none;
  color: #999;
}
.input_label.float {
  opacity: 0;
  -webkit-transform: translateY(25%);
          transform: translateY(25%);
  -webkit-transform-origin: left;
          transform-origin: left;
  transition-properties: opacity, transform;
  transition-duration: 80ms;
  transition-timing-function: ease-out;
}
.active .input_label.float {
  opacity: 1;
  -webkit-transform: none;
          transform: none;
  transition-duration: 240ms;
}

.input_text {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  font: inherit;
  background: none;
  color: inherit;
  margin: 0;
  padding: 0;
  border: none;
  box-sizing: border-box;
}

.input_text {
  width: 100%;
  height: 2em;
  padding: 0.5em 0;
  box-shadow: 0 -1px rgba(51, 51, 51, 0.2) inset;
  transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1);
}
.input_text:focus {
  outline: none;
}

textarea.input_text {
  height: calc(3rem * 1.5);
  resize: none;
}

::-webkit-input-placeholder {
  color: #999;
}

:-ms-input-placeholder {
  color: #999;
}

::-ms-input-placeholder {
  color: #999;
}

::placeholder {
  color: #999;
}

html {
  font: 16px/1.5 sans-serif;
  color: #333;
}

body {
  margin: 7.5% 0;
}

.container {
  padding: 0 1rem;
}

.contact {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.field {
  position: relative;
  margin-bottom: 20px;
}
.field::after {
  position: absolute;
  left: 0px;
  bottom: 0px;
  content: '';
  opacity: 0;
  width: 1%;
  height: 2px;
  background: #000;
  transition: 400ms;
}
.field.focused::after {
  opacity: 1;
  width: 100%;
}
JS
// Text Input
// Mudando a classe do label para animar
//
var _inputs = Array.from(document.querySelectorAll('.input_text'));
_inputs.forEach( function( element ) {

  var _this = element,
      _field = _this.parentElement;

  _this.onfocus = function() {
    _field.classList.add('focused');
  };

  _this.onkeyup = function() {
    _activeField( _this, _field );
  };

  _this.onblur = function() {
    _activeField( _this, _field );
    _field.classList.remove('focused');
  };

});

function _activeField( element, field ) {
  if ( element.value )
    field.classList.add('active');
  else
    field.classList.remove('active');
}
Term
Sat, 04/14/2018 - 20:43

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv