Tips for stopping the textarea from moving around as you type and avoid it hitting the bottom of the page: Utilize JQuery and

As I type into the auto-sizing textarea, the text runs to the bottom of the page and causes it to dance uncontrollably with each key press. This forces me to constantly scroll down to see what's happening. How can I prevent this page dancing and keep the text from running off the bottom?

To replicate the issue, please refer to this JS Fiddle: https://jsfiddle.net/osbnnbxa/

The problem seems most prominent in IE10 (slight dancing in Firefox). As the client primarily uses IE10, a solution specific to this browser is required.

Below is the HTML code snippet:

<div>
 <div>
  <br><br> &nbsp;&nbsp;
    <textarea class="normal" name="myarea" id="myarea" style="height: 100px; overflow-y: hidden;"></textarea>
  </div>
</div> 
<input type="button" class="butt" value="ehehehhe" />

JQuery implementation:

var myquery = {
  autoHeight: function(e) {
  $(e).css({
  'height': 'auto',
  'overflow-y': 'hidden'
 }).height(e.scrollHeight);
},
init: function() {
setTimeout(function() {
  $('textarea').each(function() {
    myquery.autoHeight(this);
  }).on('input', function() {
    myquery.autoHeight(this);
  });
}, 200);
$("textarea").keypress(function(e) {
   $(".butt").focus();    
   $(this).focus();    
});
  }

};

$(myquery.init);

Update: The customer has requested not to define the maximum height of the textarea. It should expand as the text increases.

Answer №1

Although you recommended allowing the textarea to flow freely, I found a different solution that I really prefer. The modification I made in your fiddle causes the textarea to expand almost to the bottom of the viewport and eliminates all erratic movements. This adjustment represents a fair compromise, in my opinion. Check out the updated fiddle here.

textarea {
  max-height: 85vh;
}

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

Seeking assistance with using JavaScript to filter posts from Contentful for a Next.js website

Currently, I am integrating a Next.js blog with Contentful and employing queries to display posts on the homepage. While I can easily use .filter() to feature certain posts based on a boolean value, I am struggling to figure out how to fetch posts that mat ...

I'm encountering some puzzling errors from the Codacy feature in GitHub that are leaving me completely baffled

I'm currently using Codacy in my code repository to assess the quality of my work. Struggling with two errors during commit, unsure how to troubleshoot them. Can anyone offer assistance? Issue: Expected property shorthand. Error occurs in this line ...

What is the best way to style the current element being targeted in React?

In my React application, I am trying to dynamically adjust the height of a textarea element based on its content. I want to achieve this by utilizing an 'onchange' listener to trigger a resize function. While I have successfully implemented the ...

Uninstalling NPM License Checker version

Utilizing the npm license checker tool found at https://www.npmjs.com/package/license-checker The configuration in license-format.json for the customPath is as follows: { "name": "", "version": false, "description&quo ...

Repetitive outcomes are observed when iterating through elements with Selenium in Python

I'm currently facing a puzzling issue that has me stumped. My HTML contains a ul list with multiple li items, each of which includes elements I need to extract using Selenium in Python. The structure of the website is as follows: <ul id="results"& ...

Introducing Enhanced Google ReCaptcha Verification and Pre-Submission Evaluation

I'm new to PHP, jQuery, and AJAX. I'm attempting to integrate the new Google Recapcha. It appears as follows - After Click- And After verified- The code in index.php is as follows- <html> <head> <title>Google reCAPTCHA ...

Does it follow standard practice for Array.filter to have the capability to also perform mapping on an array of objects?

While experimenting with Array.filter, I made an interesting discovery. By forgetting to include an equality check, my array was unexpectedly mapped instead of filtered. Here is the code snippet that led to this result: const x = [{ name: 'user' ...

What is the reason behind the immediate firing of the animate callback function when a CSS transition is present?

I am facing an issue where the callback function fires immediately, disregarding the linear ease type and defaulting to the swing ease in CSS transitions. Is there a way to ensure that the animate function works correctly with the transition? The reason fo ...

iOS - Embedding text into a UIWebView input field

Just a quick question - if a textfield in a webform does not automatically have the focus set by the form, meaning you have to press the field before the keyboard pops up, am I correct in assuming that the field cannot be edited? In simpler terms - is it ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...

Tips for sending and showcasing a multi-dimensional array using ajax

Currently, I am implementing my project with an Object-Oriented Programming approach. One of the tasks involves passing all database values in the form of a multidimensional array through AJAX, displaying the array using 'text' datatype in consol ...

The 'mergeMap' property is not found on the 'Observable<any>' type

Currently, I'm working on an HttpInterceptor within my Ionic 4 application. My goal is to retrieve the Bearer Authorization token stored in local storage. Although I attempted to utilize mergeMap for this task, I kept encountering the following error ...

Displaying AJAX data in a table format, showcasing 10 rows of information

I am currently working on an ajax function that retrieves data from a database based on the entered information. My goal is to display this information in a table with the following format: System Id | Last Name | First Name | Middle Name | Address Below ...

Effortless AJAX/jQuery solution for displaying live file updates while copying

As I delve into the world of Ajax/jQuery, my current focus is on setting up a test environment for the following scenario: The server needs to recursively copy an entire folder from one location to another. The client should then display the list of copi ...

Customize the Header Background Color in React Table

I'm working on customizing a re-useable table component using vanilla CSS. I have defined six color variables and want users to be able to select one of them to change the table header background color. However, I am unsure how to make this color choi ...

How can you use jQuery to identify when new tweets have been loaded?

Have you ever noticed that when you reach the bottom of a profile page (not the timeline), new tweets are loaded automatically? I am working on a UserScript and I want to trigger a function every time those new tweets are loaded. The challenge I'm fa ...

Touch Screen Button Interaction

Planning to create a Kiosk website with HTML5 that includes point and drag & drop functionality. The site will have buttons and images for user interaction, with actions triggered by finger touches on the screen instead of mouse clicks. Would it be more ...

Finding a specific section on a webpage using AngularJS

Is it possible to create in-page navigation to a specific section within an Angular application without triggering the routing service? For example: The section we want to jump to: <a name="tips"> <div>Tips and tricks...</div> < ...

The error message "TypeError: 'undefined' is not an object ('_this.props')" indicates that the property '_this

Having trouble solving this issue. Need assistance with evaluating 'this.props.speciesSelection.modalize' <BarcodeInput speciesSelection={this.props.speciesSelection} species={species[0]} barcode={{ manufacturerValue: ...

Store the content of an HTML div using HTML5 Drag and Drop functionality in a MYSQL database

Here's a simple scenario: I have 3 small divs (1, 2, 3) and I want to place them inside 3 other divs (4, 5, 6). That's no issue, but then I need to store the data in MySQL, such as 4-1, 5-2, 6-3 for instance. I can use JavaScript to display the n ...