在鼠标上输入输入字段展开

On mouse enter input field Expand

我想在输入鼠标时扩展输入字段以填充条目,或者在移开鼠标时折叠其原始宽度。

我的Html代码

<div class="col-xs-4">
<input type="text" class="form-control" placeholder="All India" >
</div>
<div class="col-xs-6">
<input type="text"  id="service" class="form-control" placeholder="What Service Do You Need Today ?">
</div>

脚本

$('#service').click(function() {
         $('#service').css({
         'width': '134%'
         });
});

JsFiddle

你可以试试这个:

$('#service').click(function() {
             $('#service').css({
             'width': '134%'
             });
     return:false;

        });

DEMO

您可以使用JQuery的'Focus'方法:

$('#service').on('focus',function() {
    $('#service').css({'width': '134%'});
}); 

希望对您有所帮助。

要在聚焦时调整大小然后聚焦:

$('#service').on('focusin',function() {
    $('#service').css({'width': '134%'});
});
$('#service').on('focusout',function() {
     $('#service').css({'width': ''});
});

Codepen http://codepen.io/noobskie/pen/pjEdqv

您正在寻找悬停功能吗?

$( "#service" ).hover(
  function() {
    $( this ).css({'width': '134%'});
  }, function() {
    $( this ).css({'width': '100%'});
  }
);

编辑

更新后的 codepen 在 mouseleave 事件上单击将输入扩展到 134% returns 恢复正常

$( "#service" ).click(
  function() {
    $( this ).css({'width': '134%'});
  }
);
$( "#service" ).mouseout(function() {
    $( this ).css({'width': '100%'});
});

要么使用

$('#service').on('blur',function() { 

         $('#service').css({
         'width': '100%'
         });

    });

$('#service').on('mouseleave',function() {

         $('#service').css({
         'width': '100%'
         });

    });

您好,现在您可以尝试 focus and blur

$( "#service" ).focus(function() {
  $('#service').css({ 'width': '134%' });
});

$( "#service" ).blur(function() {
  $('#service').css({ 'width': '100%' });
});

Demo

试试这个:

$('#service')
  .on('focusin',function() {
    $(this).width('134%');
  })
  .on('focusout',function() {
     $(this).width('100%');
  });