Last active
March 22, 2017 22:10
-
-
Save david-cako/8102cafc635754e5efa40c1e34d32727 to your computer and use it in GitHub Desktop.
bootstrap 4 expanding text fields (flexbox) | demo here: https://jsfiddle.net/dum1rkxq/
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
#text-field { | |
flex: 1 1 0; | |
} | |
#neighbouring-div { | |
margin-left: 10px; | |
} |
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
<div class="container-fluid"> | |
<div class="row" style="width: 400px"> | |
<input id="text-field" type="text" class="form-control"> | |
<div id="neighbouring-div"> | |
<button type="button" class="btn btn-primary"> | |
submit | |
</button> | |
<button type="button" class="btn btn-danger"> | |
cancel | |
</button> | |
</div> | |
</div> | |
</div> |
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
$('#text-field').focus(function() { | |
var filenameInput = $(this); | |
var newWidth = $(this).css("width"); | |
$("#neighbouring-div").fadeOut(100, function() { | |
filenameInput.css("flex", "0 1 " + newWidth); | |
filenameInput.animate({ | |
"flex-grow": "1" | |
}, 250); | |
}); | |
}).blur(function() { | |
$(this).animate({ | |
"flex-grow": '0' | |
}, 250, function() { | |
$(this).css("flex", "1 1 0"); | |
$("#neighbouring-div").fadeIn(200); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment