Last active
August 29, 2015 14:00
-
-
Save bezenson/11344945 to your computer and use it in GitHub Desktop.
Instead of box-sizing: border-box for inputs, textarea and others
This file contains 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
function embedInputs($selector) { | |
$selector.each(function() { | |
var $this = $(this); | |
$this.width(1); | |
if($this.is('textarea')) { | |
$this.css({'min-width': '', 'max-width': ''}); | |
} | |
var additionalWidth = | |
parseInt($this.css('border-left-width')) + | |
parseInt($this.css('border-right-width')) + | |
parseInt($this.css('margin-left')) + | |
parseInt($this.css('margin-right')) + | |
parseInt($this.css('padding-left')) + | |
parseInt($this.css('padding-right')), | |
parentWidth = $this.parent().width(), | |
countedWidth = parentWidth-additionalWidth; | |
setTimeout(function() { | |
$this.width(countedWidth); | |
if($this.is('textarea')) { | |
$this.css({ | |
'min-width': countedWidth, | |
'max-width': countedWidth | |
}); | |
} | |
}, 10); // avoiding lags while window resizing (for big JS files) | |
}); | |
} |
This file contains 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
$(document).ready(embedInputs($('.embed'))); | |
$(window).resize(embedInputs($('.embed'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment