I use the jQuery .animate() function to animate the width of the <div> when the child <input> focused. However, this causes the input to jump up and down when the event fires. Something seems to be with inline-block .
HTML
<div id="simp-inputs"> <div> <label class="control-label" for="simp-date">Date: </label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></div> <input type="text" class="form-control" id="simp-date"> </div> </div> <div> <label class="control-label" for="simp-start-time">Start Time: </label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-time"></span></div> <input type="text" class="form-control" id="simp-start-time"> </div> </div> <div> <label class="control-label" for="simp-end-time">End Time: </label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-time"></span></div> <input type="text" class="form-control" id="simp-end-time"> </div> </div> <div> <label class="control-label" for="simp-comments">Comments: </label> <div class="input-group"> <div class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></div> <input type="text" class="form-control" id="simp-comments"> </div> </div> <div> <label></label> <button class="btn btn-default" role="button" id="simp-submit">Submit</button> </div> </div>
CSS
#simp-inputs > div { display: inline-block; width: 15vw; margin-right: 2em; } #simp-inputs > div:last-child { width: auto; } #simp-submit { margin-top: 65px; } #simp-inputs input { text-align: center; }
Javascript
var comments = $('#simp-comments'); comments.focusin(function() { var div = $(this).parent().parent(); div.animate({ width: '30vw' }, 300); }); comments.focusout(function() { var div = $(this).parent().parent(), val = $(this).val(); if (!val.length) { div.animate({ width: '15vw' }, 300); } });
source share