Adjust the vertical size and smoothly lower a text input field

When a user clicks on a textarea, I want it to smoothly change height to 60px and slide down in one fluid animation.

Check out the JSFiddle example here: http://jsfiddle.net/MgcDU/6399/

HTML:

<div class="container">
  <div class="well">
      <textarea style="width:462px" placeholder="Leave a comment..."></textarea>
  </div>
</div>

Thank you! :)

Answer №1

If you're looking for the solution, the method to use is known as animate() and it has extensive documentation available.

Regarding your jsfiddle example, I have crafted the necessary jQuery code to showcase how the animate method works along with the focus() and blur() methods:

jQuery(document).ready(function ($){

    var element = $('.well textarea');
    var orig_height = element.height();
    var new_height = 60;

    // Event handler for when element is focused
    element.focus(function (){
        $(this).animate({height: new_height + 'px'});
    });
    // Event handler for when element loses focus
    element.blur(function (){
        $(this).animate({height: orig_height + 'px'});
    });
});

Answer №2

How about achieving a similar result as shown in this demo?

$('.toggle').click(function() {

   $(this).toggleClass('active');

});

Answer №3

This method proves to be more effective when used in animation...

$("textarea").on('focus',function (e, ui) {
    $(this).animate({
        height: "60px"
    }, 1500);
});

Check out the jsFiddle Demo here

Answer №4

$('#comment').on('click', function () {

   $(this).fadeIn(2000, function() {
      $(this).css('width', '100px');
   });


   $(this).focusout(function() {
      $(this).css('width', '50px');
   }); 



});

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

What are the available events offered by Express websockets?

I am interested in learning about the different websocket events available. Currently, I have only used the ws.on('message') event, but I would like to find out how to detect when the connection is established and closed. I attempted to add the w ...

Tips for choosing all elements in a form that have a specific class assigned

I am attempting to target all fields in a form with a specific class name and then select all the remaining fields. This is my form: <form style="margin:20px 0" id="myform_2"> <p> Query Name : <input i ...

Having trouble getting Vue-Select2 to display properly in Vuejs?

After setting up the vue3-select2-component and following their instructions, I encountered an issue where the component was not displaying in the output on the html page, even though the code for it was present in the source code. For context, I am using ...

Tips for eliminating duplicate data entries within a row while building a table using ReactJS

Apologies for the not-so-great title, but I'm having trouble figuring out how to tackle this specific issue in reactjs. I'm struggling with creating a table where one column remains empty while the other continues to populate with data. This is ...

Error in .ajax - 'a' is not defined. If 'a' exists, call it, otherwise, display an

I am trying to understand why the following code works: var addresses = {"2-avenue-bir-hakiem": "2 Avenue Bir Hakiem", "56-rue-marcel-pagnol": "56 rue Marcel Pagnol"}; but this code does not work: var addresses = json.val; Even though my JSON output is ...

Ensuring that the last function receives all necessary data by utilizing deferred functions

How can I ensure that the function displayResults() retrieves data before displaying it? Both getResultA() and getResultB() functions utilize $.Deferred. Additionally, getResultB() relies on the results from getResultA(). function getResultA() { var def ...

Toggle visibility of various items in a to-do list, displaying only one item at a time with the use of JavaScript

I am currently working on a web project using the Laravel framework. I am struggling with implementing a feature where only the title of each to-do item is displayed, and when clicked, it should reveal the corresponding content. However, I have encountered ...

What is preventing me from loading js and css files on my web pages?

I have developed a web application using SpringMVC with Thymeleaf and I am encountering an issue while trying to load javascript and CSS on my HTML5 pages. Here is a snippet from my login.html: <html xmlns="http://www.w3.org/1999/xhtml"> <head&g ...

Achieving the resolution of a Promise amidst the failure of a separate promise

I need to handle a situation where a promise is resolved regardless of the success or failure of an ajax call. I attempted to use the following code snippet: new Promise(function(resolve, reject) { $.ajax({ url: "nonExistentURL", headers: { ...

Mastering the use of node cluster mode in conjunction with agenda cronjobs

Currently, I am utilizing nodejs and agenda to run cronjobs. With a total of 10 cronjobs in place, the process is taking longer as nodejs is single-threaded and they all run simultaneously. In an attempt to resolve this issue, I experimented with pm2 by e ...

Vue.JS and its Onclick event handler allows for dynamic and interactive

These are my two buttons: <button onclick="filterSelection('Action')">Action</button> and <button onclick="filterSelection('Adventure')">Adventure</button> Now, I'm trying to achieve the same fun ...

Experience the ultimate in slider automation with the cutting-edge power of

Here is an example of a website plugin I used on my site. You can check it out by clicking here. However, I'm having trouble automating the events that occur when the item slider is clicked. I would like to make these events happen automatically with ...

Strategies for redirecting a PDF download response from an API (using node/express) to a user interface (built with React)

I have a specific setup where the backend server generates a PDF, and when a certain endpoint is visited, it triggers the download of the PDF. However, due to security restrictions, I cannot access this endpoint directly from the frontend. To overcome this ...

What is preventing me from updating one dropdown list based on the selection made in another dropdown list?

I have a situation on a classic asp page where there are two dropdown lists: <select id="ddlState" name="ddlState" runat="server"> <option value="KY">Kentucky</option> <option value="IN" ...

The HTML file contains the complete version number of Firefox

If you're an expert in HTML, take a look at my expandable start page. I know there's room for improvement, and I'm seeking advice on automatically updating the Firefox browser version number in line 106 of the code snippet below. (Linux Mint ...

Pass the name and value of the selected option to AJAX

My goal is to use AJAX to send both the name and value of a selected option from a dropdown menu. This will allow me to launch a SQL request including the selected option. This is what I have so far: jQuery: $('#form_stadt_kanton').select(func ...

HTML tag data search using Regex

I received an HTTP request and I'm attempting to extract specific data from it using a regular expression. For instance, in this particular part of the HTML: <tr><th>Continent:</th><td class='trc'>Europe (EU)</td& ...

Tips for preventing vertical spaces between table header cells in material-UI

Is there a way to remove the vertical gaps between header cells in the MUI table? To see an example of the issue, check out this codesandbox link: https://codesandbox.io/s/mui-material-table-sticky-header-forked-euilo3?file=/tsconfig.json I have attempte ...

Step-by-step guide for activating a text box when a check box is marked

I'm looking to activate and deactivate two text boxes when a check box is selected. Currently, only one text box is enabled when the check box is checked. How can I modify my code to enable and disable two text boxes based on the check box status? Her ...

Is there a way for me to customize the appearance of the Material UI switch component when it is in the checked

I am seeking to customize the color of the switch component based on its checked and unchecked state. By default, it displays in red. My goal is to have the "ball knob" appear yellow when the switch is checked and grey when it is not. This styling must be ...