Input with snap.svg & online validation

HTML
<!-- Try writing Invalid email --> <div class="form-wrap"> <div class="input"> <label for="mail">Email address</label> <input type="email" name="mail" autocomplete="off"> </div> <svg> <path d="M0 1.5h400" fill="none"/> </svg> </div>
CSS
body { background: #002b36; font-family: 'Roboto Mono', monospace; } *:focus {outline: none;} .wrap { height: 100%; width: 100%; overflow: hidden; padding: 15px; } .form-wrap { position: relative; height: 50px; width: 400px; margin: 300px auto 0; } input { color: #fff; position: absolute; width: 100%; height: 100%; left: 0; padding-top: 5px; border: none; font-size: 1em; font-weight: 200; background: none; opacity: 0; font-family: 'Roboto Mono', monospace; transition: all 0.5s ease; } .active input{ opacity: 1; transition: all 0.5s ease 0.5s; } svg { position: absolute; left: 0; top: 100%; overflow: visible; fill: none; z-index: 5; } label { color: #fff; position: absolute; top: 15px; font-size: 1.3em; transition: all 0.5s ease; } .active label { top: 0px; font-size: 1em; color: #FF5252; transition: all 0.5s ease 0.6s; } svg path { stroke: #fff; stroke-width: 3px; } .active + svg path { stroke: #FF5252; transition: stroke 0.4s ease 0.6s; } .input { height: 100%; width: 100%; position: relative; overflow: hidden; } .input:before { content: ""; position: absolute; height: 26px; width: 3px; right: 15px; bottom: -50px; background-color: transparent; transform-origin: inherit; transform: rotate(0deg); transition: transform 0.4s ease , bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s ; } .input:after { content: ""; position: absolute; height: 26px; width: 3px; right: 15px; bottom: -50px; visibility: hidden; background-color: transparent; transform-origin: inherit; transform: rotate(0deg); transition: transform 0.4s ease, visibility 0.4s ease, bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s, height 0.2s ease 0.6s; } .valid:before { bottom: 10px; right: 16px; visibility: visible; background-color: #4CAF50 ; transform-origin: inherit; transform: rotate(40deg); transition: bottom 0.4s ease, transform 0.4s ease 0.3s; } .valid:after { bottom: 10px; height: 15px; visibility: visible; background-color: #4CAF50; transform-origin: inherit; transform: rotate(-45deg); transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s; } .invalid:before { bottom: 10px; visibility: visible; background-color: #ff5252; transform: rotate(40deg); transition: bottom 0.4s ease, transform 0.4s ease 0.3s; } .invalid:after { height: 26px; bottom: 10px; visibility: visible; background-color: #ff5252; transform: rotate(-45deg); transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s; }
JAVASCRIPT
'use strict'; var textInput = document.querySelector('input'); var textPath; var textDown = function() { textPath.animate({ d: "M0 1.5c150 40 300 30 400 0" }, 150, mina.easeout); }; var textUp = function() { textPath.animate({ d: "M0 1.5c150-18 300-18 400 0" }, 150, mina.easein); }; var textSame = function() { textPath.animate({ d: "M0 1.5h400" }, 200, mina.easein); }; var textRun = function() { setTimeout(textDown, 200); setTimeout(textUp, 400); setTimeout(textSame, 600); }; (function() { textInput.addEventListener('focus', function() { var svgText = Snap('svg'); var parentDiv = this.parentElement; textPath = svgText.select('path'); parentDiv.classList.add('active'); textRun(); this.addEventListener('blur', function() { var rg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.]{3,9})+\.([A-Za-z]{2,4})$/; this.value == 0 ? parentDiv.classList.remove('active') : null; !rg.test(this.value) && this.value != 0 ? (parentDiv.classList.remove('valid'), parentDiv.classList.add('invalid'), parentDiv.style.transformOrigin = "center") : rg.test(this.value) && this.value != 0 ? (parentDiv.classList.add('valid'), parentDiv.classList.remove('invalid'), parentDiv.style.transformOrigin = "bottom") : null; }); parentDiv.classList.remove('valid', 'invalid') }); })();
Expand for more options Login