Category Search

Design for a categorical search form.

by Fawad Ali

HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!--By Fawad Ali https://jsfiddle.net/user/9inpachi/-->
<div id="search-wrapper">
    <input id="search-type" type="hidden" name="searchType" value="" />
    <input class="search-form" type="text" name="search" placeholder="Search" />
    <div class="search-options">
      <div class="search-icon">
        <i class="fa fa-search"></i>
      </div>
      <ul id="circle-elements">
        <li data-value="All">All</li>
        <li data-value="Videos">Videos</li>
        <li data-value="Images">Images</li>
        <li data-value="News">News</li>
        <li data-value="Books">Books</li>
      </ul>
    </div>
  </div>

CSS

body{
    font-family: "Helvetica";
    background: rgb(248, 248, 248);
  }
  #search-wrapper{
    position: relative;
    width: 300px;
    padding: 100px 0;
    margin: auto;
  }
  .search-form{
    font-size: 18px;
    padding: 7px 15px;
    padding-left: 40px;
    border: 2px solid rgb(231, 172, 93);
    border-radius: 50px;
    color: rgb(231, 172, 93);
    transition: all 0.5s;
  }
  .search-form:focus{
    outline: none;
    background: rgb(231, 172, 93);
    color: white;
    transition: all 0.5s;
  }
  .search-icon i{
    font-size: 20px;
    cursor: pointer;
    color: rgb(231, 172, 93);
    transition: all 0.5s;
  }
  .search-form:focus+.search-options>.search-icon>i{
    color: white;
    transition: all .5s;
  }
  .search-icon{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 15px;
    transition: all .5s;
    z-index: 10;
  }
  ul#circle-elements{
    z-index: 9;
    position: absolute;
    border: 2px solid rgb(213, 150, 66);
    width: 200px;
    height: 200px;
    background: rgb(231, 172, 93);
    color: white;
    border-radius: 50%;
    top: 10%; left: -26%; /*for example purposes only*/
    list-style-type: none;
    margin: 0;
    padding: 0;
    transform: scale(0);
    transition: all .2s;
  }
  ul#circle-elements>li{
    position: absolute;
    margin: 90px 0px 0px 62px;
    width: 70px;
    padding: 4px;
    text-align: center;
    cursor: pointer;
    border-radius: 10px;
    -webkit-transition: all .5s linear;
    -moz-transition: all .5s linear;
    transition: all .5s linear;
  }
  ul#circle-elements>li:hover{
    background: rgb(213, 150, 66);
  }
  .search-icon:hover{
    background: white;
    padding: 15px;
    border-radius: 50%;
    left: 0px;
  }
  .search-icon:hover+ul#circle-elements{
    transform: scale(1);
    animation: linear bouncedCircle .5s;
  }
  ul#circle-elements:hover{
    transform: scale(1);
    animation: linear bouncedCircle .5s;
  }
  input::-webkit-input-placeholder,
 ...

JavaScript

var type = 1, //circle type - 1 whole, 0.5 half, 0.25 quarter
    radius = '3.7em', //distance from center
    start = -90, //shift start from 0
    $elements = $('ul#circle-elements>li'),
    numberOfElements = (type === 1) ?  $elements.length : $elements.length - 1, //adj for even distro of elements when not full circle
    slice = 360 * type / numberOfElements;

    $elements.each(function(i) {
      var $self = $(this),
          rotate = slice * i + start,
          rotateReverse = rotate * -1;

      $self.css({
          'transform': 'rotate(' + rotate + 'deg) translate(' + radius + ') rotate(' + rotateReverse + 'deg)'
      });
    });
    $('ul#circle-elements>li').click(function(){
      var searchType = $(this).attr("data-value");
      $("#search-type").val(searchType);$
      $(".search-form").attr("placeholder", searchType);
      $('ul#circle-elements').css("transform", "scale(0)");
    })
    $(".search-icon").hover(function(){
      $('ul#circle-elements').css("transform", "");
    })
    $('ul#circle-elements>li').hover(function(){
      var init = -140;
      $('.search-icon i').css("transform", "rotateZ("+init+"deg)");
      if($(this).index() == 0){
        $(".search-icon i").css("transform", "rotateZ("+init+"deg)");
      }else if($(this).index() == 1){
        $(".search-icon i").css("transform", "rotateZ("+(init+75)+"deg)");
      }else if($(this).index() == 2){
        $(".search-icon i").css("transform", "rotateZ("+(init+150)+"deg)");
      }else if($(this).index() == 3){
        $(".search-icon i").css("transform", "rotateZ("+(init+220)+"deg)");
      }else if($(this).index() == 4){
        $(".search-icon i").css("transform", "rotateZ("+(init+300)+"deg)");
      }
    });
    $("ul#circle-elements").hover(function(){
      $(".search-icon").css("background", "white");
      $(".search-icon").css("padding", "15px");
      $(".search-icon").css("border-radius", "50%");
      $(".search-icon").css("left", "0px");
    })
   ...