JavaScript how can i create a search bar that slide to the left on clicking the label

I'd like to achieve this effect via css and possibly jQuery. That is to create a search bar that is hidden, and will nicely slide to the left on clicking the search icon in the label. But I just couldn't. I did manage to achieve something but it was rather boring. I want transition is to lookalike the one that is in W3school and many other websites. Here is my code:

   <nav> 
       <ul>
           <li><a target='_blank' href="#">Home</a></li>
           <li><a target='_blank' href="#">About</a></li>
           <li><a target='_blank' href="#">Contac</a></li>
     </ul>  

       <div id="search-enclose">
            <form>
                 <div id="label-enclose">
                      <label></labe>
                 </div>
                 <div id="input-enclose">
                      <input type="text" placeholder="Enter Keyword">
                 </div>
                 </form>
                 </div>
   </nav>

CSS:

 nav {
          position: relative;
     }
     ul {
          position: absolute;
          left: 25%;
          list-stye: none;
          z-index: 10;
       }
      li{
          float: right;
        }
        #search-enclose {
             width: 500px;
        }
        #label-enclose {
              position: absolute;
              top: 46px;
              left: 30%;
              height: 35px;
              width: 60px;
              line-height: 35px;
              z-index: 20;
         }

              #label-enclose label {
              display: block;
              height: 35px;
              width: 60px;
              cursor: pointer;
            }

            #input-enclose {
                 position: absolute;
                 top: 46px;
                 width: 300px;
                 height: 35px;
                  z-index: 5;
                 overflow: hidden;

                  }
                  #input {
                      display: block;
                      position: absolute;
                      width: 270px;
                      height: 35px;
                      margin: 0;
                      border: none;
                      color: #fff;
                      font-size: 18px;
                      backface-visibility: none;
                      border-radius: 0;
                      transition: left 0;   
                       }

                  #input-enclose input:focus {
                        outline: none;
                      }

                 #input-enclose .focus {
                       display: block;
                     }

                   #input-enclose .focus input {
                        left: 0;
                        transition: left 0.3s;
                      }

JavaScript

 var searchImage = document.getElementById('img');
        var input = document.getElementById('input');
         searchImage.addEventListener('click', function() {
                    if (classie.hasClass(input,'focus')) {
                    classie.removeClass(input,'focus')
                   }else {
                       classie.addClass(input, 'focus')
                       }
           }); 

For what its worth this is almost a copy of a code i found online, My formatting and css my be terrible, but i know what i want, with a good direction, i can achieve that. Just wanted the search bar to be shown atop the navigation list items, when clicked in a nice way, i did thought the CSS transition could achieve that, but it didnt. Can anybody please give me a direction to follow?

Answer:1

On label click it animate to left: Using JQuery animation:

HTML:

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<nav> 
   <ul>
       <li onclick="animateMe()" ><a target='_blank' href="#">Home</a></li> 
       <li onclick="animateMe()"><a target='_blank' href="#">About</a></li>
       <li onclick="animateMe()"><a target='_blank' href="#">Contac</a></li>
 </ul>  
<br>
<br>
   <div id="search-enclose" >
        <form>
             <div id="label-enclose">
                  <label></labe>
             </div>
             <div id="input-enclose">
                  <input type="text" placeholder="Enter Keyword">
             </div>
             </form>
             </div>
</nav>

JS:

 var searchImage = document.getElementById('img');
             var input = document.getElementById('input');
             searchImage.addEventListener('click', function() {
                    if (classie.hasClass(input,'focus')) {
                    classie.removeClass(input,'focus')
                   }else {
                       classie.addClass(input, 'focus')
                       }
                       }) 
   function animateMe(){
   $("#search-enclose").css({left:left}).animate({"left":"0%"}, "slow");
   }

CSS:

nav {
          position: relative;
     }
     ul {
          position: absolute;
          left: 25%;
          list-stye: none;
          z-index: 10;
       }
      li{
          float: right;
        }
        #search-enclose {
             width: 500px;
             position :absolute;
             left:20%;
        }
        #label-enclose {
              position: absolute;
              top: 46px;
              left: 30%;
              height: 35px;
              width: 60px;
              line-height: 35px;
              z-index: 20;
              display:none;
         }

              #label-enclose label {
              display: block;
              height: 35px;
              width: 60px;
              cursor: pointer;
            }

            #input-enclose {
                 position: absolute;
                 top: 46px;
                 width: 300px;
                 height: 35px;
                  z-index: 5;
                 overflow: hidden;

                  }
                  #input {
                      display: block;
                      position: absolute;
                      width: 270px;
                      height: 35px;
                      margin: 0;
                      border: none;
                      color: #fff;
                      font-size: 18px;
                      backface-visibility: none;
                      border-radius: 0;
                      transition: left 0;   
                       }

                  #input-enclose input:focus {
                        outline: none;
                      }

                 #input-enclose .focus {
                       display: block;
                     }

                   #input-enclose .focus input {
                        left: 0;
                        transition: left 0.3s;
                      }
Answer:2

I am using the FullCalendar plugin for my calendar. I am trying to loop through some ajax data I have acquired and populate my calendar with the relevant fields I want to use. This is what i'm doing:...

I am using the FullCalendar plugin for my calendar. I am trying to loop through some ajax data I have acquired and populate my calendar with the relevant fields I want to use. This is what i'm doing:...

  1. jquery fullcalendar eventclick
  2. jquery fullcalendar eventclick get date
  3. jquery fullcalendar trigger event click
  4. jquery fullcalendar event click not working
  5. jquery fullcalendar event right click
  6. fullcalendar eventclick

I have a route like this path: 'projects/:id/settings' And in my header.component.html I want to have a link to this page <a routerLink="['projects', progectId,'settings']" routerLinkActive="...

I have a route like this path: 'projects/:id/settings' And in my header.component.html I want to have a link to this page <a routerLink="['projects', progectId,'settings']" routerLinkActive="...

  1. angular router link active
  2. angular router link not working
  3. angular router link button
  4. angular routerlink example
  5. angular router link params
  6. angular routerlink with data
  7. angular routerlink new tab
  8. angular router link conditional
  9. angular router link with query params
  10. angular router link on click
  11. angular router link disable
  12. angular router link reload page
  13. angular router link go back
  14. angular routerlink to parent
  15. angular router link state
  16. angular router link active class
  17. angular routerlink variable
  18. angular router link relative path
  19. angular routerlink anchor tag
  20. angular router link active css

I would like to clear the textarea content after enter key press on react. However when enter key press the text area clears but the enter key remains (new line). How can I fix this? constructor(){ ...

I would like to clear the textarea content after enter key press on react. However when enter key press the text area clears but the enter key remains (new line). How can I fix this? constructor(){ ...

  1. clear textarea after submit
  2. clear textarea after submit react
  3. clear textarea after submit angular
  4. clear textarea after enter
  5. clear textarea after submit ajax
  6. clear textarea after submit angularjs
  7. clear textarea after submission
  8. javascript clear textarea after submit
  9. php clear textarea after submit
  10. jquery clear textarea after enter
  11. clear textarea value after click

There is a onclick function tied up with this tag. I need to trigger this onclick function, so I used page.sendEvent('click', element.offsetLeft, element.offsetTop, 'left'); But it ...

There is a onclick function tied up with this tag. I need to trigger this onclick function, so I used page.sendEvent('click', element.offsetLeft, element.offsetTop, 'left'); But it ...