Adjust the size of the text and the textarea at the same time

I am trying to resize text simultaneously while resizing the textarea in my code. I am using jQuery for this functionality. However, I believe there is an issue with the click function being separated. Any advice on how to fix this would be greatly appreciated.

Unfortunately, I cannot post the JsFiddle link directly but you can find it here: http://jsfiddle.net/mr_eirenaios/Tr92Q/8/

$("#aTx").click(function () {
    $("#DVtx").append('<textarea rows="3" id="aText">Type Here</textarea>');
});
var diagonalScl;
var txSiz;
$(function () {
    $("#DVtx").resizable({
        alsoResize: '#aText',
        create: function (event, ui) {
            diagonalScl = diagonalSwItms();
            txSiz = parseInt($("#aText").css("font-size"));
        },
        resize: function (e, ui) {
            var diagonalSclNw = diagonalSwItms();
            var ratio = diagonalSclNw / diagonalScl;
            $("#aText").css("font-size", txSiz + ratio * 3);
        }
    });
});

function diagonalSwItms() {
    var contentWidth = $("#aText").width();
    var contentHeght = $("#aText").height();
    return contentWidth * contentWidth + contentHeght * contentHeght;
}

Answer №1

FlowType.js is the key to perfect typographic harmony, like a melody for the mind.

Answer №2

I just tackled this in a fresh code snippet, take a peek at http://jsfiddle.net/p4YKH/9/ I applied the

stop event when resizing the element
and after checking your font size calculation, it seems to be returning an inaccurate value, so I suggest trying a different approach for determining the font size with a minor tweak to the code.

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 is the best method for locating the innermost element of an HTML tree that has a specific class assigned

I am working on a project that involves a menu system. One of the features I am implementing is that when a tree within the menu is opened, it receives the "active" class. My goal now is to dynamically retrieve the deepest sub-menu within this structure ...

redactor.js: Disable backspace functionality when cursor is at the start of a div-container

Currently, I am working with the redactor.js editor that utilizes editable div containers. A challenge I have encountered is when multiple contenteditable containers are nested; deleting content using the backspace button can inadvertently delete the entir ...

Steps for embedding a "string includes" functionality within an Angular filter

Currently, I am in the process of implementing a filtering system using checkboxes. Within my geojson data, there is a property called "status" which can have values like: status : "Act 3Q99" or status : "Fut 3Q99" My objective is to filte ...

Tips for effectively incorporating additional directives into a directive as it is being defined

I'm encountering a significant issue with dynamic directives in angularjs. My goal is to include new directives to a directive while defining it through an object: compile: function () { return { pre: function (scope, iElement, iAttrs) { ...

Accessing elements in a JSON object was straightforward with the

I need help with accessing values from a JSON object based on a key name stored in a variable. My colleague has written a function to extract keys from the JSON object and compare them with the ones we are interested in. However, I am struggling with fig ...

`Optimizing Performance using jQuery Functions and AJAX`

As someone exploring ajax for the first time, I'm eager to learn how to write jQuery code that ensures my simple functions like slideshows and overlays still work smoothly when a page is loaded via ajax. Currently, I am implementing the following met ...

I'm having trouble pinpointing the cause of the never-ending loop in this React code that is using Material UI grid

There seems to be an issue with infinite looping in this code, and I can't figure out the cause, import React, { useEffect, useState } from 'react'; import VideoCardComponent from './VideoCard'; import Grid from '@mui/material ...

The passport is experiencing an authentication issue: The subclass must override the Strategy#authenticate method

After attempting to authenticate and log in a user, I encountered an error message stating: Strategy#authenticate must be overridden by subclass. How can I resolve this issue? What could be causing this error to occur? Concerning Passport.js const LocalS ...

How to pass an item as a parameter to a computed property in Vue.js, and have it return a sorted child array within a

After spending some time searching on Google, I am still struggling to find a solution for this issue. I have a list of "Intents" that contain nested lists of "Entities" created using v-for loops. The Intents are already computed, but now I need to dynam ...

Avoid transitioning to a different page using Vue-router

I have recently ventured into the world of Vue.js and my current project involves fetching data from an API, implementing pagination, and creating a detailed view for each post upon clicking. I have successfully implemented the pagination feature, however, ...

Searching for effective methods to deliver reset password notifications to users

Seeking advice on sending password reset emails to users who have forgotten their passwords. Interested in various suggestions and methods for implementing this feature. I have a simple script that prompts users to click a 'forgot password' link ...

Is there a way to set up a saving path using xhtml2pdf and provide a download link

I am currently using xhtml2pdf to convert my form into a PDF file. By default, it saves the PDF in the same location as my manage.py file. My question is how can I change the saving path to send the PDF to my Desktop, for example (running MacOSX). Below ...

Dnd-kit: item loses its place in line when dragged over Droppable area

I've encountered an issue while using @dnd-kit. The sorting function works smoothly (e.g. when I drag the 1st element, it sorts correctly), but once I reach a droppable element (green Thrash), the sorting breaks and the 1st element snaps back. You ca ...

Why does the text in a div display in Safari 8.2 and Chrome 39, but not in Firefox 34?

In my HTML document, I have a div tag located within the body like so: <div id="content_text"></div>​ Using javascript, I later set the contents of the div like this: var content_text = document.getElementById("content_text") c ...

Establish a route nickname for files outside the project directory

I'm currently tackling a project that is divided into multiple angular projects. Within these projects, there are some services that are shared. Is there a way for me to incorporate these services into my project without encountering errors? /root / ...

Troubleshoot: Issues arising when loading DataTables using AJAX with MYSQL

For some reason, I'm receiving an invalid JSON response from this code. The objective is to showcase SQL data in a table with search and sort functionalities using https://datatables.net/. Can you pinpoint where the issue might lie? GET.PHP $mysqli ...

The animation of a disappearing div with CSS is not stopping when hovering over it

Hello, I've been working on a snackbar feature that appears and disappears on a set timer but also needs to pause when hovered over. Unfortunately, the current setup with setTimeout and useState is causing issues with this functionality. I have looke ...

Angular 4, Trouble: Unable to resolve parameters for StateObservable: (?)

I've been working on writing unit tests for one of my services but keep encountering an error: "Can't resolve all parameters for StateObservable: (?)". As a result, my test is failing. Can someone please help me identify and fix the issue? Here& ...

File upload - Obtain details of file prior to its upload on the server platform

Is there a way to get file information (like file size) before uploading it to the server? I'm developing a multi-file upload feature using JQuery, but I need to determine the size of the files in order to set a limit by calculating the total size of ...

Insert a new row into the table and populate it with data entered into the input field

My setup involves a table and a form containing two input fields. Once the user enters data into the input fields and clicks save, it gets added as a new row in the table. If the user types again and clicks save, the old entries are replaced with the new ...