Forked from DerZyklop's Pen cqkbn.
Created
June 26, 2014 15:16
-
-
Save DerZyklop/db74fc557d61e3ed760d to your computer and use it in GitHub Desktop.
A Pen by DerZyklop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input maxlength="5" type="text" name="nix" placeholder="Schreib..." value=""> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input[maxlength]').on 'keydown', -> | |
if !$(this).parent().hasClass('maxlengthwrap') | |
$(this).wrap('<div class="maxlengthwrap"></div>').focus() | |
maxlength = parseInt($(this).attr('maxlength')) | |
currlength = $(this).val().length | |
if maxlength == currlength | |
$(this).on 'keyup', -> | |
currlength = $(this).val().length | |
if maxlength == currlength && !$(this).parent().find('.overlay').length | |
# set overlay | |
$(this).after('<div class="overlay">Max. '+maxlength+' Zeichen</div>') | |
overlayTimeout = | |
setOverlayTimeout = => | |
overlayTimeout = setTimeout => | |
$(this).parent().find('.overlay').fadeOut -> $(this).remove() | |
, 1000 | |
# remove it a moment later | |
setOverlayTimeout() | |
# show a little longer if user keeps trying | |
$(this).on 'keydown', -> | |
clearTimeout overlayTimeout | |
setOverlayTimeout() | |
else | |
$(this).off('keyup') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input | |
box-sizing: border-box /* css3 rec */ | |
-moz-box-sizing: border-box /* ff2 */ | |
-ms-box-sizing: border-box /* ie8 */ | |
-webkit-box-sizing: border-box /* safari3 */ | |
-khtml-box-sizing: border-box /* konqueror */ | |
display: block | |
width: 100% | |
.maxlengthwrap | |
position: relative | |
.overlay | |
position: absolute | |
line-height: inherit | |
top: 0 | |
bottom: 0 | |
left: 0 | |
right: 0 | |
background: rgba(200,30,0,1) | |
color: #fff | |
/* untouchable */ | |
-moz-user-select: none | |
-khtml-user-select: none | |
-webkit-user-select: none | |
/* IE 10 */ | |
-ms-user-select: none | |
user-select: none | |
/* Remove this */ | |
body | |
background: #eee | |
padding: 5em | |
input, | |
.maxlengthwrap .overlay | |
font-family: monospace | |
border-radius: 4px | |
border: 1px solid #ccc | |
padding: 1em | |
font-size: 1.4em | |
line-height: 1em |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment