Tips for moving an input bar aside to make room for another

Is it feasible to have two input bars next to each other and keep one open until the other is clicked, then the first one closes as well? I attempted using a transition with "autofocus," but the bar ends up closing when clicked on in my site.

If anyone can implement this functionality using JavaScript, that would be greatly appreciated!

Check out the Fiddle here

Need some assistance?

HTML:

<div id='Sidebar'>
<div id='SMBar'>
    <div id="input-bars">
        <!-- SEARCH BAR -->
        <div id="SearchBar">
            <form id="tfnewsearch" method="get" action="URL">
                <input type="text" class="search-text-input" placeholder="Search Posts..." name="q" />
            </form>
            <div class="tfclear"></div>
        </div>
        <!-- EMAIL BAR -->
        <div id="FollowByEmail1">
            <form action="URL" method="post" target="popupwindow" onsubmit="window.open('URL', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">
                <p>
                    <input autofocus="autofocus" class="follow-by-email-address" placeholder="Updates by Email..." type="text" name="email" />
                </p>
                <input type="hidden" value="" name="uri" />
                <input type="hidden" name="loc" value="en_US" />
            </form>
        </div>
    </div>
</div>

CSS:

#Sidebar {
width: 270px;
border: 1px solid transparent;
height: 500px;
}
#SMBar {
border: 1px solid transparent;
margin: 5px;
height: 405px;
}
#input-bars {
border: 1px solid transparent;
margin: 5px;
height: 30px;
}
input {
height: 25px;
font-size: 14px;
font-family: Play;
padding-left: 30px;
width: 0px;
transition-property: width;
transition-duration: 1s;
background-repeat: no-repeat;
border-radius: 5px;
border: 1px solid black;
outline: none;
box-shadow: 0px 0px 9px #dddddd;
-moz-box-shadow: 0px 0px 9px #dddddd;
-webkit-box-shadow: 0px 0px 9px #dddddd;
}
input:focus {
width: 170px;
box-shadow: 0px 0px 4px #000000;
-moz-box-shadow: 0px 0px 4px #000000;
-webkit-box-shadow: 0px 0px 4px #000000;
}
.follow-by-email-address {
background-image: url(http://imageshack.com/a/img703/8868/iavu.png);
padding-left: 30px;
margin: -12px 0px 0px 2px;
float: left;
}
.search-text-input {
background-image: url(http://imageshack.com/a/img34/9278/cw35.png);
padding-left: 30px;
float: right;
margin: 0px 2px 0px 0px;
}

Answer №1

Check out this jQuery example DEMO

I made some changes to the initial width of .follow-by-email-address, setting it to 170px. I also removed the CSS selector input:focus and added the following script:

$(document).ready(function(){
    $('.follow-by-email-address').focus(function(){
        $(this).animate({
            width: 170
        }, 500);
        $('.search-text-input').animate({
            width: 0
        },500);
    });

    $('.search-text-input').focus(function(){
        $(this).animate({
            width: 170
        }, 500);
        $('.follow-by-email-address').animate({
            width: 0
        },500);
    });
});

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

Prevent issues with text overlap in HTML and CSS

My text is overlapping when I resize the window. How can I prevent this? I want the text to resize only if it collides with other elements, or stack under each other if resizing is not possible. problem I've already attempted using flex box setting ...

The animations in three.js have come to a standstill

Currently, I am working on a real-time game using three.js and websockets. The project has been running smoothly until recently when I encountered a hurdle. While implementing animations, I noticed that the animations for the opposing client on the web pag ...

Vue component always renders a new line

Whenever I include a <component> tag in my main application, it always renders on a new line. Is there a way to make it inline? I am trying to achieve something like this: <p>This is a component :<component></component></p> & ...

Tips for adjusting the placeholder color in Material UI using React JS

Is there a way to customize the background color and flashing color of the Skeleton component in Material UI? I would like to implement custom styling for it, similar to what is shown below: <Skeleton variant="circle" classes={{root:'pla ...

ng-class does not seem to be functioning properly when used within a file that is included via ng-include in

My question pertains to the menu I am loading using ng-include from the index file. <span ng-include="'app/components/common/menu.html'"></span> The content of menu.html is as follows: <li ng-class="active" > <a hr ...

Using Javascript, verify if a given URL is legitimate and commences with "http://" or "https://"

I need to validate the authenticity of my URLs, ensuring they begin with either http:// or https://. Here is the regular expression (RegExp) I have been using: private testIfValidURL(str) { const pattern = new RegExp('^(https?:\\/&bsol ...

What is the best way to set up a clickable image without making the entire div clickable?

Is it possible to make just a specific image clickable within a div without making the entire div clickable? I have an image inside an anchor tag and a surrounding div that is clickable. The issue is that the entire space around the first image, .home, is ...

Information is not appearing in the table

I'm having trouble displaying data in a table format. The issue arises when I try to fetch data from a JSON file using a custom service. The fetched data is then inserted into the $rootScope object. However, when I preview the view, it appears blank ...

Verify that JavaScript is capable of performing mathematical operations such as addition and multiplication successfully

When dealing with a specific set of "Strings" that represent integers in an addition operation, how can one determine if the calculation is feasible in javascript? For example: 2 + 2 (certainly possible) 20000000000000000 - 1 (impossible) 2e50 + 2e60 (i ...

What is the best way to utilize the outcome of the initial API request when making a second API call in AngularJS

Looking to utilize the response of a first API call in a second API call. The situation is such that I need to fetch data from the first API and use it in the second API call. I believe a synchronous API call would be necessary. While attempting to imple ...

How can I merge an array of objects in lodash?

I am facing a challenge with merging an array of objects in JavaScript. My goal is to combine them into a single object using either a JS library or lodash. Here is how my array looks: [{ 2017: { a: "100", b: "200" ...

What is the best way to position a div below another sticky div when the first div's height is constantly changing

I am facing a challenge with scrollable text and sticky headers on my webpage. The top text has dynamic height based on the content below, which is followed by a sticky header with its own dynamic height. Now, I want to add another sticky header below the ...

Redux state assigns object to another object

I started with an initial state that looks like this: let initialState = { items: [ { name: 'a' }, { name: 'b' } ], otherItems: [] } I am attempting to copy the items array and assign i ...

Display the modal in Angular 8 only after receiving the response from submitting the form

I am encountering an issue where a pop-up is being displayed immediately upon clicking the submit button in Angular 8, before receiving a response. I would like the modal to only appear after obtaining the response. Can someone assist me with achieving thi ...

Emulating a Javascript API request

I'm looking to practice simulating API calls for a VueJS application. Currently, I am fetching data from a hardcoded JSON file that I've created. Within my App.vue: <template> <p>{{ teams.yankees.city }}</p> // Output will b ...

What is the best way to position my logo on top of the stunning space background?

Click here to check out the code on CodePen Please take a look at my code on codepen.io. I am new to Stack Overflow so please be patient with me if I make any mistakes. ;-; I currently have my logo (https://i.stack.imgur.com/W0nWc.png) included in the co ...

Steps for generating a time selection dropdown menu

My issue is with the functionality of my timepicker dropdown. Below is the code I am currently using: $(document).ready(function() { $('.timepicker-input').timepicker({ timeFormat: 'h:mm p', interval: 60, minTime: ' ...

Unable to retrieve the JSON response item

Currently, I am in the process of setting up an AJAX call with the intention of manipulating the response data. Upon inspecting my browser's network console, this is the response I am seeing: { "message": "success", "file": "dump.xml" } Thi ...

Transforming a React application from ES6 hooks to Class-based components

Hello, I am new to React and currently facing a challenge in converting the following code into a Class Based Component. Despite knowing that I am going in the opposite direction, I am unable to figure out how to proceed without encountering errors. Any ...

Refreshing a specific div within an HTML page

I am facing an issue with the navigation on my website. Currently, I have a div on the left side of the page containing a nav bar. However, when a user clicks a link in the nav bar, only the content on the right side of the page changes. Is there a way t ...