label.placeholder { position: relative; &:after { display: flex; align-items: center; content: attr(data-placeholder); position: absolute; top:0; right: 0; bottom: 0; left: $after-left; font-size: 14px; color: grey; cursor: text; transition: transform $tf-duration $tf, opacity $tf-duration $tf; transform: translateX(0); opacity: 1; color: $input-default-color; } &.hidden { &:after { transform: translateX(40%); opacity: 0; } } }
$(document).ready(function() { function placeholderAnimation() { var $placeholder = $('input[placeholder]'); $placeholder.each(function () { $(this).wrap('<label class="placeholder" data-placeholder="' + this.placeholder + '">').attr('placeholder', ''); }).on('keyup', function () { $(this).parent().toggleClass('hidden', this.value !== ''); }); } placeholderAnimation(); });
Source: https://habr.com/ru/post/265497/
All Articles