Expand input with :focus
by JQ Purfect
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css">
<div class="box">
<div class="icon">
<div class="search">
<div class="input-group">
<input type="text" class="form-control txt" placeholder="project name..." aria-describedby="basic-addon2">
<span class="input-group-addon" id="basic-addon2"><i class="fa fa-check add"></i></span>
<span class="input-group-addon" id="basic-addon2"><i class="fa fa-times clear"></i></span>
</div>
</div>
</div>
</div>
<small class="msg" style="display:none;">New Project created...</small>
CSS
body {
margin: 50px;
}
.box {
width: 420px;
}
.search {
width: 300px;
max-width: 0;
transition: all .5s ease;
box-sizing: border-box;
opacity: 0;
}
.search.expanded {
max-width: 300px;
opacity: 1;
}
.icon {
width: 30px;
height: 30px;
background: #fff;
right: 0;
background-image: url("//assets.windowsphone.com/d12e7853-4cf7-4b33-bc93-d21f60e2e6fa/basic-icon-plus_InvariantCulture_Default.png");
background-repeat: no-repeat;
}
small {
color: #a9a9a9;
padding: 15px;
position: absolute;
top: 42px;
left: 72px;
}
JavaScript
$('.icon').click(function() {
$('.search').addClass('expanded');
$(".msg").hide();
$(".txt").val('');
});
$(".icon").keypress(function(e) {
if (e.which == 13) {
alert('Capture the new project addition...');
$(".msg").show();
$('.search').removeClass('expanded');
}
});
$(".add").click(function(e) {
e.stopPropagation();
alert('Capture the new project addition...');
$(".msg").show();
$('.search').removeClass('expanded');
});
$(".clear").click(function(e) {
e.stopPropagation();
alert("cancel..");
$('.search').removeClass('expanded');
});