Function mouseout on icon

Asked

Viewed 227 times

1

inserir a descrição da imagem aqui

I would like when hovering over the search icon to load an input field.

html

<div id="navbar" class="navbar-collapse collapse pull-right">
      <ul class="nav navbar-nav">
          <li><a href="contato"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a></li>
      </ul>

</div> <!-- /#navbar -->
  • 1

    Put the menu structure in HTML that you have there.

  • Sorry, I didn’t see that I had run out of HTML.

  • What error are you getting? What code did you try and didn’t work? Are you using some tool?

  • @Moshmage, I wasn’t using a code, because I didn’t know how to do it. I tried to search the net but I didn’t find anything.

1 answer

1

You can use to add a "listener" to the event type mouseover, when listening to this event, you add a input where you want it. Likewise, you should remove the inputwhen user takes mouse from input, listening to an event of the type mouseout. Let me give you an example where when you take the mouse out the input does not go out, but when the user takes the focus of the input.

$(function() {
  $("#contato").on("mouseover", function() {
    $(this).parent().prepend("<input class='form-control input-lg' type='text' placeholder='Pesquisar..'/>");
    $(this).parent().find("input").focus().on("blur", function() {
      $(this).remove();
    });
  });

});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<ul class="nav navbar-nav">
  <li><a href="contato" id="contato"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
  </li>
</ul>

Do a test by hovering over the icon then clicking out to lose the focus of the input.

The details will depend on you now.

Alternatively, you can use the plugin Expadingsearchbar.

  • I will study the code you gave me and also give an eye on the plugin you suggested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.