Leveraging jQuery's .animate method to create engaging search box animations

Greetings esteemed individuals...

I am currently working on enhancing the search component for my application...

http://jsfiddle.net/SkyKOG/K8utq/24/

input{
    display:none;
    width:0px;
    color:#999;
}

Initially, I only had a simple search box so the existing functions are tailored for that. However, the new requirement is different...

The text box should be hidden initially and should only expand upon clicking on the search icon. I tried using display:none and click events, but didn't have success with it...

Thank you very much...

Best regards

Answer №1

if this is the functionality you are looking for.

Try using the click event of the icon to toggle the textbox in conjunction with the rest of your code.

 $('#searchinout').find('i').click(function(){
    $('#expandbox').toggle('slow');
});

Also, add this snippet to your CSS file:

#expandbox{
  display:none;
}

Click here for a live example on JSFiddle.

Answer №2

$(document).ready(function () {

//hide the search bar initially
$("#txtSearch").hide();

//show the search bar when search icon is clicked
$(".Search").click(function () {
$("#txtSearch").show();
});

});

Alternatively, you can hide the textbox by setting its display property to none and then change it to block when the search icon is clicked.

Answer №3

Feel free to experiment with the following code:

input{
    width:0px;
    color:#999;
    opacity:0;
}

var inputWidth = '200px';
var inputWidthReturn = '0px';   

$(document).ready(function() {
  $('.icon-search').click(function(){
    //animate the box
    $('#expandbox').animate({
      width: inputWidth,
      opacity: 1
    }, 800 )
    $('#expandbox').focus();
  }); 

  $('#expandbox').blur(function(){
    $(this).animate({
      width: inputWidthReturn,
      opacity: 0
    }, 800 )

  });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjusting the line height of an inline-block div causes surrounding inline-block siblings to shift downward

As I venture into exploring the line-height property, I came across information on MDN which stated: For non-replaced inline elements, it determines the height used in calculating the line box height. However, in this scenario, when I set the line-heigh ...

Once the hidden DIV is revealed, the Youtube video within it begins to load

I currently have a hidden DIV on my website that contains a YouTube clip. My goal is to load the video in the background once the page has fully loaded, so that it's ready to play when the user clicks the button to reveal the DIV. However, at the mo ...

Unlock the potential of Vue custom props within the asyncData function in your nuxtjs project!

I have a special function in my project that serves as a plugin import Vue from 'vue' function duplicateText(text) { var input = document.createElement('input'); input.setAttribute('value', text); document.body.a ...

What is the reason behind my titles being triple the length they should be?

Here is my personal website The titles are appropriately set for the About College section Note: Utilizing Purl library for this purpose var seg2 = ''; if (url.segment(2) == 'college-life') seg2 = "College Life"; else if (url.seg ...

I am looking to implement a permanent change using PHP Ajax

I am facing an issue with the "Add as Buddy" button on my webpage. I want it to change permanently to "Pending Request" once clicked, but it keeps reverting back to "Add as Buddy" whenever I refresh the page. Can anyone suggest a solution for this problem? ...

Chargebee encountered an error of type TypeError when attempting to create a subscription. The action

Every time I attempt to send a request with Chargebee, an error appears. Error: Failed to create subscription async createSubscriptionForTeamMember(customerId, options) { try { // Proceed with subscription creation using Chargebee API ...

Ways to confirm non-null values and bypass the row if it is

I have been attempting to compare 2 dates in order to appropriately display data in a table. I have tried the following approach: ${this.dateToCompare.getTime()} > ${row.CreateDate.getTime()} However, there is an issue where CreateDate has a null value ...

Text Overlapping Issue in React Material UI Components

I am currently working on a React application using Material UI and facing an issue while implementing an entity update page. The task at hand is to display the existing values of the entity for the user to update. To achieve this, I have set the default v ...

Signal for a complete 360 degree rotation of an image

Looking to enhance my 360 image rotator with an indicator that fades out after the first image. I added this function to the end of my 360.js: (function(){ if( $('#first').css('visibility','hidden')) { $('#rotat ...

iOS - A clever trick for manually setting focus on an input/textarea

Recently, there have been numerous discussions about the issue in iOS where focusing on an input/textarea element cannot be achieved through manual means. (Check out the threads here and here) It appears that iOS necessitates a genuine tap or click for foc ...

Footer overflows content

My footer is getting overlapped by the slideshow on my webpage. I have already attempted to clear the previous DIV in the source code as per the usual recommendation: <div class="clear"></div><!-- /clear any floats --> However, this sol ...

Is there another option besides using the iframe element in jQuery version 2.1.3?

Please refer to the jQuery source code at: . Upon searching for the text "<iframe", you will find the following function: function defaultDisplay( nodeName ) { var doc = document, display = elemdisplay[ nodeName ]; if ( !display ) { ...

The Meteor Call object stands apart from the Meteor Method object that was received

When I send an object from the client to the server using a Meteor Call and Meteor method, something strange happens. The object is received in the Method but it looks different - nested within the giftList. Meteor Call - JSON.stringify {"personName& ...

I'm in the process of developing a React application that will display live sensor data in graph form

My current project involves building a react app that visualizes real-time data from IoT sensors, including temperature, humidity, and pressure. I want the app to store this data so users can log in at any time to view specific information based on time, d ...

Validate if the translation file exists in ngx-translate

Is there a way to determine if a translation file exists for the language obtained from navigator.language using ngx-translate? I am looking to implement something similar to: if( isLanguageAvailable(navigator.language)) { this.translate.use(navigator.l ...

Verifying File Extension in PHP Form Upload

Hey there! I'm currently working on a PHP contact form where I need to check for errors in the submission. Everything seems to be working fine except for one part - the file upload validation. If the file extension is not allowed (like a PHP file), th ...

At times, Vue.js may encounter difficulties when attempting to load a component

Recently, a strange issue has been occurring in my production code. Although nothing has been changed, I am now receiving reports that occasionally a template fails to load causing the page to crash. I am currently using vue 2.16. The error messages being ...

Minimizing the Height of HTML Table Rows

I have a table with a few rows. I'm trying to set the height of the 1st and 3rd rows to 1px and keep the 2nd row at normal height. However, my code isn't working as expected. Here is the HTML CODE: <table border="0"> <tr style="hei ...

Is there a way for me to delay sending an immediate response until the asynchronous loop has completed?

Currently trying to implement something similar to the code snippet below. I suspect that the issue lies within the asynchronous call as it seems like the response I am getting is always an empty array, despite the API returning data. As a beginner in th ...

Ways to resolve encoded titles in Youtube API search results

I am currently utilizing the youtube-search 1.1.4 package to search for videos. However, I am encountering an issue where the titles of the results are encoded with &amp; or &#39; instead of simply & and ' and so forth. For instance, an e ...