Самый необычный способ показать и скрыть пароль в поле на CSS3 и Javascript
Пожалуй, самый оригинальный способ показа и скрытия пароля в поле
Для начала посмотрите ДЕМО
Установка:
1#: В самый низ вашего CSS вставьте:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
:root { --light-grey: #e0e0e0; --dark-grey: #c5c5c5; } body * { box-sizing: border-box; outline: none; } .container { width: 210px; position: relative; } input { background: #ececec; border: 0; font-size: 1em; width: 100%; box-shadow: 0.15em 0.15em 0.25em var(--dark-grey) inset, -0.15em -0.15em 0.25em #ffffff80 inset, 0.3em 0.3em 0.6em var(--dark-grey), -0.2em -0.2em 0.5em #ffffff80; border-radius: 4px; padding: 10px; position: absolute; z-index: 1; height: 40px; color: #808080; font-family: monospace, Arial, Helvetica, sans-serif; } input::placeholder { color: #808080; opacity: 1; } input:-ms-input-placeholder { color: #808080; } input::-ms-input-placeholder { color: #808080; } input.active { animation: scanning 1s ease 0s 1; background: linear-gradient(90deg, #02de0b 50%, #ececec 100%); background-repeat: no-repeat; background-position: -210px; background-color: #ececec; } @keyframes scanning { 0% { background-position: 150px; } 100% { background-position: -210px; } } #reveal { width: 40px; height: 40px; border-radius: 4px; border: 0; background: linear-gradient(145deg, #72c0ff, #0070ca); cursor: pointer; position: absolute; z-index: 3; right: 0px; box-shadow: 0.3em 0.3em 0.6em var(--dark-grey), -0.2em -0.2em 0.5em #fff; border: 2px solid var(--light-grey); transition: all 0.5s ease 0s; border-top-color: #cccccc; border-bottom-color: #eee; } #reveal:before { content: ""; background: radial-gradient( circle at center, #00000080 1px, #00000080 2px, #00000080 3px, #00000080 4px ); width: 18px; height: 18px; border-radius: 0 100%; transform: rotate(-45deg) skew(-10deg, -10deg); left: 9px; position: absolute; top: 9px; transition: all 0.25s ease 0s; } #reveal:after { content: ""; width: 20px; height: 18px; border-radius: 100%; left: 6px; top: 4px; position: absolute; border: 2px dotted #fff0; border-bottom-color: #00000080; transition: all 0.25s ease 0s; } #reveal:disabled { transition: all 0.5s ease 0s; background: linear-gradient(145deg, #ced5e0, #757575) !important; cursor: default; } #reveal.open { transition: all 0.5s ease 0s; background: linear-gradient(145deg, #8ce88f, #009205); } #reveal.open:after { transform: rotateX(-180deg); top: 10px; background: radial-gradient( circle at 50% 12px, #00000000 1px, #ececec 2px, #ffffff 3px, #00000000 4px ); } #reveal span:before { display: none; font-family: monospace; } #reveal:hover span:before { content: "Показать пароль"; display: block; position: absolute; background: #4fa8ef; top: -4.5em; padding: 0.45em 0.5em; left: -0.9em; border-radius: 2px; font-size: 0.85em; color: #1d4c72; min-height: 2.25em; } #reveal:hover span:after { content: ""; display: block; position: absolute; border: 0.7em solid transparent; border-top-color: #4fa8ef; left: 0.7em; top: -1.15em; } #reveal.open:hover span:before { content: "Скрыть пароль"; background: #61cd64 !important; color: #215d23; } #reveal.open:hover span:after { border-top-color: #61cd64; } #reveal[disabled="disabled"]:hover span:before { content: "Пароль пуст"; background: #b3b8c0 !important; color: #4d4e51; } #reveal[disabled="disabled"]:hover span:after { border-top-color: #b3b8c0; } #fakepass { font-size: 1em; width: 0%; border-radius: 4px 0 0 4px; position: absolute; background: #ececec; z-index: 2; height: 40px; top: 0; right: 0; left: 0; transition: all 1s ease 0s; width: 0; line-height: 40px; text-indent: 10px; overflow: hidden; box-shadow: 0.15em 0.15em 0.25em var(--dark-grey) inset, -0.15em -0.15em 0.25em #ffffff80 inset; animation: scan-hide 1s ease-out 0s 1; color: #808080; } #fakepass:before { content: ""; height: 40px; width: 0px; position: absolute; right: 13px; top: 0; box-shadow: -10px 0 20px 10px #33a4ffad, 0 0 10px 5px #33a4ffab; } #fakepass.scan { display: block; animation: scan-show 1s ease-out 0s 1; width: 0%; left: 0; } #fakepass.scan:before { display: none; } #fakepass:after { content: ""; height: 40px; width: 2px; background: #92ceff; position: absolute; right: 10px; top: 0; box-shadow: 0 0 3px 1px #33a4ff, 0 0 5px 3px #33a4ff; animation: light 0.15s ease 0s infinite; } #fakepass.scan:after { background: #07ff10; box-shadow: 0 0 3px 1px #00cc08, 0 0 5px 3px #00cc08; right: 5px; } @keyframes light { 50% { opacity: 0.5; } } @keyframes scan-show { 0% { width: 100%; } 100% { width: 0%; } } @keyframes scan-hide { 0% { width: 0%; left: 0; right: inherit; } 98% { width: 100%; left: 0; right: inherit; } 99% { width: 100%; left: inherit; right: 0; } 100% { width: 0%; left: inherit; right: 0; } } @-moz-document url-prefix() { #fakepass { text-shadow: 0 0 2px #666, 0 0 2px #666, 0 0 2px #666, 0 0 2px #666, 0 0 2px #666, 0 0 2px #666, 0 0 2px #666, 0 0 2px #666; } } |
2#: Следующий код вставьте между тегами <body> и </body>:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<div class="container"> <input id="pass" type="password" placeholder="Пароль"> <span id="fakepass">Пароль</span> <button id="reveal" disabled="disabled"><span></span></button> </div> <script type="text/javascript"> var btn = document.getElementById('reveal'); var box = document.getElementById('pass'); var fak = document.getElementById('fakepass'); const isEmpty = str => !str.trim().length; btn.addEventListener('click', function() { fak.innerHTML=''; var x = box.value.length; for(var i=0; i<x; i++ ){fak.innerHTML=fak.innerHTML+'•';} fak.classList.toggle('scan'); this.classList.toggle('open'); box.classList.toggle('active'); (box.type=='password') ? box.type='text' : setTimeout(function(){ box.type='password' }, 500);; }); box.addEventListener("input", function() { if(!isEmpty(this.value)) btn.removeAttribute('disabled'); else btn.setAttribute('disabled', 'disabled'); }); </script> |