Last active
January 9, 2018 07:29
-
-
Save KryptikOne/8073410 to your computer and use it in GitHub Desktop.
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
| $('textarea').keyup(function() { | |
| var characterCount = $(this).val().length, | |
| current = $('#current'), | |
| maximum = $('#maximum'), | |
| theCount = $('#the-count'); | |
| current.text(characterCount); | |
| /* ===| This isn't entirely necessary, just playin around |=== */ | |
| if (characterCount < 70) { | |
| current.css('color', '#666'); | |
| } | |
| if (characterCount > 70 && characterCount < 90) { | |
| current.css('color', '#6d5555'); | |
| } | |
| if (characterCount > 90 && characterCount < 100) { | |
| current.css('color', '#793535'); | |
| } | |
| if (characterCount > 100 && characterCount < 120) { | |
| current.css('color', '#841c1c'); | |
| } | |
| if (characterCount > 120 && characterCount < 139) { | |
| current.css('color', '#8f0001'); | |
| } | |
| if (characterCount == 140) { | |
| maximum.css('color', '#8f0001'); | |
| current.css('color', '#8f0001'); | |
| theCount.css('font-weight','bold'); | |
| } else { | |
| maximum.css('color','#666'); | |
| theCount.css('font-weight','normal'); | |
| } | |
| }); |
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
| <div class="wrapper"> | |
| <h1>Displaying Character Count of a Textarea</h1> | |
| <textarea name="the-textarea" id="the-textarea" maxlength="140" placeholder="Enter Your Text Here"></textarea> | |
| <div id="the-count"> | |
| <span id="current">0</span> | |
| <span id="maximum">/ 140</span> | |
| </div> | |
| </div> |
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
| @import url(http://fonts.googleapis.com/css?family=Open+Sans:300,700,300italic); | |
| *, *:before, *:after { box-sizing: border-box; } | |
| html { font-size: 100%; } | |
| body { | |
| font-family: 'Open Sans', sans-serif; | |
| font-size: 16px; | |
| background: #abc5e3; | |
| color: #666; | |
| } | |
| .wrapper { | |
| max-width: 50%; | |
| margin: auto; | |
| } | |
| h1 { | |
| color: #777; | |
| margin: 3rem 0 1rem 0; | |
| padding: 0; | |
| font-size: 1.5rem; | |
| } | |
| textarea { | |
| width: 100%; | |
| min-height: 100px; | |
| resize: none; | |
| border-radius: 8px; | |
| border: 1px solid #ddd; | |
| padding: 0.5rem; | |
| color: #666; | |
| box-shadow: inset 0 0 0.25rem #ddd; | |
| &:focus { | |
| outline: none; | |
| border: 1px solid darken(#ddd, 5%); | |
| box-shadow: inset 0 0 0.5rem darken(#ddd, 5%); | |
| } | |
| &[placeholder] { | |
| font-style: italic; | |
| font-size: 0.875rem; | |
| } | |
| } | |
| #the-count { | |
| float: right; | |
| padding: 0.1rem 0 0 0; | |
| font-size: 0.875rem; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you pls tell how to count "tab space, backspace, delete" into account . how to add tab functionality into this?