rajudhaka

Search bar toggle

Aug 1st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Html markup
  2.     <div class="search-wrap">
  3.       <form class="search-inner" method="get">
  4.         <input class="searchinput" type="search" placeholder="Search..." autocomplete="off">
  5.         <button type="submit" name="button" id="searchbtn"><i class="fas fa-search"></i></button>
  6.       </form>
  7.     </div>
  8.  
  9.     <a href="" class="searchIcon">
  10.       <i class="fas fa-search"></i>
  11.     </a>
  12.  
  13. (function ($) {
  14.     "use strict";
  15.    /*==========================================================
  16.      header search wrap
  17.      ======================================================================*/
  18.  
  19.     if ($(".search-wrap").length > 0) {
  20.         var todg = true;
  21.         $(".searchIcon").on("click", function (e) {
  22.             e.preventDefault();
  23.             if (todg) {
  24.                 $(".search-wrap").fadeIn("slow");
  25.                 todg = false;
  26.             } else {
  27.                 $(".search-wrap").fadeOut("slow");
  28.                 todg = true;
  29.             }
  30.         });
  31.  
  32.         $(document).on('mouseup', function (e) {
  33.             var container = $(".search-inner");
  34.  
  35.             if (!container.is(e.target) && container.has(e.target).length === 0) {
  36.                 $(".search-wrap").fadeOut("slow");
  37.                 todg = true;
  38.             }
  39.  
  40.         });
  41.     }
  42.  
  43. })(jQuery);
  44.  
  45. .search-wrap {
  46.     background: rgba(0, 0, 0, 0.8);
  47.     cursor: url(cross-cursor.png), pointer;
  48.     position: fixed;
  49.     top: 0;
  50.     right: 0;
  51.     bottom: 0;
  52.     z-index: 999;
  53.     left: 0;
  54.     display: none;
  55.   }
  56.  
  57.   .search-inner {
  58.     height: 50px;
  59.     width: 50%;
  60.     margin: auto;
  61.     position: absolute;
  62.     top: 24%;
  63.     left: 0;
  64.     right: 0;
  65.     margin: auto; }
  66.  
  67.   .search-inner input[type="search"] {
  68.     width: 100%;
  69.     background: transparent;
  70.     border: none;
  71.     border-bottom-width: medium;
  72.     border-bottom-style: none;
  73.     border-bottom-color: currentcolor;
  74.     border-bottom: 2px solid #bdbbbb;
  75.     font-size: 18px;
  76.     color: #fff;
  77.     padding: 10px 27px 18px 10px;
  78.     font-style: italic;
  79.     line-height: 1; }
  80.     .search-inner input[type="search"]::-webkit-input-placeholder {
  81.       color: #fff; }
  82.     .search-inner input[type="search"]:-ms-input-placeholder {
  83.       color: #fff; }
  84.     .search-inner input[type="search"]::-ms-input-placeholder {
  85.       color: #fff; }
  86.     .search-inner input[type="search"]::placeholder {
  87.       color: #fff; }
  88.  
  89.   .search-inner button {
  90.     position: absolute;
  91.     right: 10px;
  92.     top: 8px;
  93.     background: transparent;
  94.     border: none;
  95.     font-size: 18px;
  96.     color: #fff;
  97.     cursor: pointer;
  98.     outline: none; }
Advertisement
Add Comment
Please, Sign In to add comment