使用jquery在悬停时展开文本表单
Expand text form on hover with jquery
我有一个引导程序文本输入,使用jquery我想:
-
悬停时展开文本表单,悬停时收回。✓(已经在这个jsfiddle中完成)
-
当聚焦/选择文本表单时(插入点在文本框内),当光标悬停在外时,表单将展开且不会缩回。✗
Html
<div class="col-md-3 col-sm-3">
<div class="input-group">
<input class="form-control" placeholder="Search"></input>
</div>
</div>
Javascript
$(function(){
var form = $('.input-group');
form.mouseenter(function(){
form.animate({ "width": "+=" + form.width() * 1.4}, "slow");
}).mouseout(function(){
form.animate({ "width": '100%'}, "slow");
});
});
尝试这个
$(function(){
var form = $('.input-group');
var start_width = form.width();
form.find('#input-target').mouseenter(function(){
form.animate({ "width": "+=" + start_width * 1.4}, "slow");
}).mouseout(function(){
form.animate({ "width": start_width+'px'}, "slow");
}).focus(function(){
$(this).unbind('mouseout');
$(this).unbind('mouseenter');
}).blur(function(){
form.animate({ "width": start_width+'px'}, "slow");
$(this).mouseout(function(){
form.animate({ "width": start_width+'px'}, "slow");
}).mouseenter(function(){
form.animate({ "width": "+=" + start_width * 1.4}, "slow");
});
});
});
看看这个http://jsfiddle.net/ZQ3nZ/
已解决http://jsfiddle.net/mY8uU/6/
$(function(){
var form = $('.input-group'), w = form.width();
form.mouseenter(function(){
form.animate({'width': '100%'}, 'slow');
}).mouseout(function(){
if(!$('.form-control:focus').length) form.animate({'width': w}, 'slow');
})
$('.form-control').on('blur', function(){
form.animate({'width': w}, 'slow');
});
});
CSS3是不可能的吗?
在这种情况下,您可以不使用Javascript并使用
.textbox{
width: 200px;
transition: width 1S;
}
.textbox:hover
{
width:250px;
transition: width 1S;
}
这只是一个例子,但你可以根据自己的喜好进行更改。
您总是可以使用一些CSS3:
input#search {
transition: width .5s;
-webkit-transition: width .5s;
}
input#search:hover, input#search:focus { width:300px; }
这个对我有用:
$(function(){
var form = $('.input-group');
form.mouseenter(function(){
form.animate({ "width": form.width() * 1.8}, "slow");
}).mouseout(function(){
form.animate({ "width": form.width() / 1.8}, "slow");
});
});
jsfiddle:http://jsfiddle.net/mY8uU/2/
相关文章:
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 输入文本框为空时的阻止按钮asp.网络表单
- 或者在表单上选择默认选项文本(选择1)
- 提交表单后,Watir文本框输入未持续(重置为以前的文本框输入)
- 提交表单时,Javascript(JQuery)不会在文本区域中填充内容
- 表单输入字段随着溢出的文本而增长
- 表单文本框未自动更新
- 使用javascript提交表单并从字段/单选框/复选框/文本区域获取数据
- 单击时从表单中删除特定文本
- 在HTML表单中键入时返回文本
- 使用jquery在悬停时展开文本表单
- 将从服务器获取的数据加载到输入文本表单中
- 如何使用文本表单输入的一部分来添加并使其转到 URL
- 将HTML中的文本表单值输入到Javascript函数中
- JS救援文本表单
- 使用crypto.js创建文本表单生成器
- 如何在将逗号提交到服务器之前,使用JS删除输入文本表单中的逗号
- 文件上传和数据(文本)表单转化为HTML表格
- Javascript禁用/启用输入文本表单
- 输入文本表单,使用javascript清除并恢复表单内容的问题