Animated CSS JQuery Search Box For Blogger & WordPress

Hello friends, in this tutorial I will like to show you how you can create a really cool animated CSS Animated Search Box for your websites and blogs.
Many on you had heard about cool CSS widgets for websites and even you’ve tested them once. As far as i’ve concerned, lots of users are opted on Blogging today. Most of them are using WordPress and Blogger for posting various articles on the internet. This is really good example of social media sharing.

To start off, you will need the following tools:

  • CSS3 for styling and animations
  • HTML for the structure
  • JavaScript and jQuery as the manager of our demonstration.

How To Add Animated Search Box on your Blog?

Follow the steps mentioned below properly to add this beautiful search box widget to your blog. Both WordPress and Blogger users can add this widget on their blog as well as other users such as Joomla,Drupal and other sources.

Part 1 : HTML

First of all, we have a container, div, with “search-wrapper” class. This will hold and center our search box.
The first children element of our primary container is called .input-holder. This one has a fixed width in our main container .search-wrapper. The .input-holder contains the text input and the search button.

Remember:

  • The text input is positioned absolute and stretched on the full length of his “parent”
  • The search button has the CSS float property with the value of right, in order to keep it on the right side of our container while animating it.

The second children element of our div is called .close ,and it acts as a container for the close icon, created using the CSS pseudo classes ::before and ::after.

<div class="search-wrapper">
<div class="input-holder">
<input class="search-input" placeholder="Type to search" type="text" />
        <button class="search-icon" onclick="searchToggle(this, event);"></button>
    </div>
<span class="close" onclick="searchToggle(this, event);"></span>
</div>

Part 2 : CSS

Note: In order to have a light code structure and easy to read article, I will not add the vendors prefixes for any CSS property. You can easily find the complete source on the DEMO page, or in the DOWNLOAD link.
Since our demonstration is about animating with CSS, I will insist on explaining the CSS animation/ transition techniques, and not on the casual CSS properties. Now, let’s take a close look at the way I centered the main wrapper, .search-wrapper, and talk about that :

.search-wrapper {
    position: absolute;
    transform: translate(-50%, -50%);
    top:50%;
    left:50%;
}
.search-wrapper.active {}

First of all, to center an element in the middle of the document, you’ll need to use position:absolute , and set the top and left side to 50%. You have the result of that in bullet 1 in the picture below.
Next, you will see that the top-left side of the element is positioned in the middle of the document, but that’s not exactly what we want. So by using CSS3 property transform:translate(x,y) , where “x” and “y” are -50%, you will be able to subtract 50% of your current element’s width and height from the current position. See bullet 2!
Note: Before having CSS transform at our disposal, we used to calculate that offset with JavaScript, and you know how annoying that was, right, developers?

Now let’s see . input-holder :

.search-wrapper .input-holder {    
    height: 70px;
    width:70px;
    overflow: hidden;
    background: rgba(255,255,255,0);
    border-radius:6px;
    position: relative;
    transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder {
    width:450px;
    border-radius: 50px;
    background: rgba(0,0,0,0.5);
    transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
}

The .input-holder has 2 different transitions, one using the ease-in-out predefined timing function (that applies when you close the search box), and the second one using cubic-bezier timing function (that applies when you expand it).
.input-holder has 2 values for width, one for the closed state, and another for the expanded state. Same thing with the border-radius and background properties.
Moving forward with .input-holder, we have the text input (.search-input) and the search button (.search-icon):

.search-wrapper .input-holder .search-input {
    width:100%;
    height: 50px;
    padding:0px 70px 0 20px;
    opacity: 0;
    position: absolute;
    top:0px;
    left:0px;
    background: transparent;
    box-sizing: border-box;
    border:none;
    outline:none;
    font-family:"Open Sans", Arial, Verdana;
    font-size: 16px;
    font-weight: 400;
    line-height: 20px;
    color:#FFF;
    transform: translate(0, 60px);
    transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition-delay: 0.3s;
}
.search-wrapper.active .input-holder .search-input {
    opacity: 1;
    transform: translate(0, 10px);
}
.search-wrapper .input-holder .search-icon {
    width:70px;
    height:70px;
    border:none;
    border-radius:6px;
    background: #FFF;
    padding:0px;
    outline:none;
    position: relative;
    z-index: 2;
    float:right;
    cursor: pointer;
    transition: all 0.3s ease-in-out;
}
.search-wrapper.active .input-holder .search-icon {
    width: 50px;
    height:50px;
    margin: 10px;
    border-radius: 30px;
}
.search-wrapper .input-holder .search-icon span {
    width:22px;
    height:22px;
    display: inline-block;
    vertical-align: middle;
    position:relative;
    transform: rotate(45deg);
    transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);
}
.search-wrapper.active .input-holder .search-icon span {
    transform: rotate(-45deg);
}
.search-wrapper .input-holder .search-icon span::before,
.search-wrapper .input-holder .search-icon span::after {
    position: absolute; 
    content:'';
}
.search-wrapper .input-holder .search-icon span::before {
    width: 4px;
    height: 11px;
    left: 9px;
    top: 18px;
    border-radius: 2px;
    background: #FE5F55;
}
.search-wrapper .input-holder .search-icon span::after {
    width: 14px;
    height: 14px;
    left: 0px;
    top: 0px;
    border-radius: 16px;
    border: 4px solid #FE5F55;
}
.search-wrapper .close {
    position: absolute;
    z-index: 1;
    top:24px;
    right:20px;
    width:25px;
    height:25px;
    cursor: pointer;
    transform: rotate(-180deg);
    transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
    transition-delay: 0.2s;
}
.search-wrapper.active .close {
    right:-50px;
    transform: rotate(45deg);
    transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition-delay: 0.5s;
}
.search-wrapper .close::before, .search-wrapper .close::after {
    position:absolute;
    content:'';
    background: #FE5F55;
    border-radius: 2px;
}
.search-wrapper .close::before {
    width: 5px;
    height: 25px;
    left: 10px;
    top: 0px;
}
.search-wrapper .close::after {
    width: 25px;
    height: 5px;
    left: 0px;
    top: 10px;
}

As mentioned above in the HTML part of this tutorial, the .search-input has position:absolute, stretched at 100%. This means that it takes the value of his parent.

For the animation, we have 2 states:

When the .input-holder closes, we apply a few CSS3 properties on .search-input : transform:translate (0,60px), this moves the search input on y axis (bottom) with 60 pixels opacity:0 (self explanatory) transition-delay: 3s, this allows delaying the transition with 3 milliseconds, to have a more interactive animationthe last thing we need to do is to apply a transition that has a cubic-bezier timing function with a 3 milliseconds duration, transition:all.3s cubic-bezier (0.000,0.105,0.035,1.570)When the .input-holder opens, we switch the opacity from 0 to 1 and transform from translate (0,60px) to translate (0,10px). As for the transition property, it’s inherited from the previous state.The .search-icon and .close use the same methods for the transition as described earlier, with a few differences, such as using the transition property in conjunction with transform:rotate (x deg). This allows us to rotate our element around its own center.
In the HTML part of our tutorial, I’ve mentioned how some of the icons are created with CSS pseudo classes, ::before and ::after. When using before and after pseudo classes, you have the possibility of inserting content before or after the content of the selected element. You can create a lot of cool stuff, such as icons, but we’ll share more info about this in future articles.
To close this section, I want to let you know that I’ve used a lot of transitions to achieve the desired animations, and a lot of cubic-bezier. If you want to get the best animations using transitions, my advice would be to check out some cubic-bezier documentation and tutorials.

Part 3: JavaScript

Before doing anything else, you will need to include jQuery for this to work. Notice that our main wrapper, .search-wrapper has a .active class attached in the CSS. We’ll use this class for toggling between the states of the main wrapper child.
The searchToggle() function adds or removes the .active class from .search-wrapper in a toggle like fashion.

<script type="text/javascript">
function searchToggle(obj, evt){
    var container = $(obj).closest('.search-wrapper');
        if(!container.hasClass('active')){
            container.addClass('active');
            evt.preventDefault();
        }
        else if(container.hasClass('active') &&
        $(obj).closest('.input-holder').length == 0){
            container.removeClass('active');
            // clear input
            container.find('.search-input').val('');
        }
}</script>

You can also download the code for this search box widget. Just tap on the download button below to proceed.
DOWNLOAD CODE

Final Words

So this was the article on Animated CSS JQuery Search Box For Blogger & WordPress. I’m sure it will clear all your consequences about this article on your mind. Now you have known all the facts about Animated CSS-JQuery Filter clearly. I hope you love this article.

Leave a Reply

Your email address will not be published. Required fields are marked *

Releated

Best Android Homescreen Customization For 2018 (Nova Launcher + Zooper Widget)

Android Homescreen Customization 2018 Android is the most popular operating system over the mobile platform today. It has lots of features and specifications. One of the most amazing feature of android is its ability to customize the device. So today we will discuss on Homescreen Customization. Lets roll over it. What is Android Homescreen? Android Homescreen is the […]