Last active
December 15, 2015 09:19
-
-
Save kingkorf/5237312 to your computer and use it in GitHub Desktop.
Responsive input jQuery plugin
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($) { | |
$.fn.responsiveInput = function() { | |
var $this = this; | |
$(window).resize(function() { | |
resizeInput($this); | |
}); | |
var resizeInput = function($this) { | |
var def = 100; | |
var width = 0; | |
$this.each(function(key, item) { | |
var $item = $(item); | |
var $parent = $item.parent(); | |
width = $parent[0].offsetWidth; | |
var padding_right = $parent.css("padding-right"); | |
var padding_left = $parent.css("padding-left"); | |
width -= (parseInt(padding_right) + parseInt(padding_left)); | |
var input_padding_right = $item.css("padding-right"); | |
var input_padding_left = $item.css("padding-left"); | |
width -= (parseInt(input_padding_right) + parseInt(input_padding_left)); | |
var input_border_right = $item.css("border-right-width"); | |
var input_border_left = $item.css("border-left-width"); | |
width -= (parseInt(input_border_right) + parseInt(input_border_left)); | |
percent = $item.data('width') ? $item.data('width') : def; | |
$item.width((width / 100) * percent); | |
}); | |
} | |
resizeInput($this); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment