What is the most efficient method for identifying and modifying an element's in-line style while performing a swipe gesture?

Recently, I've been developing a left swipe gesture handler for chat bubbles. Implementing touchMove and touchStart seems like the logical next step, but for now, I'm focusing on making it work seamlessly for PC/web users.

I managed to make it functional, but I believe there must be a more efficient way than constantly updating the inline transform style for each bubble. The current implementation doesn't feel as smooth as I envisioned.

I even experimented with a somewhat "hacky" approach using scroll-snap, but couldn't quite get it to function properly.

While my preference is a pure CSS solution, I'm open to other suggestions. Is the method outlined below the only viable option?

const { createRoot } = ReactDOM;
const { StrictMode, useEffect, useState } = React;

// Rest of the JavaScript code...
* {
  outline: none;
  box-sizing: border-box;
  margin: 0;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
}

// Rest of the CSS code...
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>

Here's how it currently appears:

https://i.stack.imgur.com/DrucZ.gif

Answer №1

Your work was impressive, but there is an even more optimized solution using only CSS. Create a resizable transparent div for your bubble, and then use another div as a resizable icon to control its size. By dragging this second div, you can adjust the size of the bubble and also move it horizontally. For detailed instructions on how to achieve this, check out this helpful article: https://css-tricks.com/books/greatest-css-tricks/draggable-elements/

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

How to programmatically close a colorbox using an ASP.NET form's Submit button within an iframe

I've looked at other similar questions, but I just can't seem to make this work. I want to close the colorbox iframe when a .NET Button form within the iframe is clicked. <script type="text/javascript"> $(document).ready(function() { ...

ReactJS component not triggering OnChange event in IE 11

While exploring the React.js documentation, I came across a suggestion to use the onChange event for text areas. Interestingly, when I tried pasting some text into an empty IE 11 text area, the onChange event failed to trigger. Surprisingly, it worked perf ...

Retrieve information from the index resource using AJAX

I feel like I might be overcomplicating things, but basically, I'm trying to retrieve all the data from an index resource and have it load when a button is clicked using AJAX. I've been using a serializer to tidy up the JSON. Both "/categories" ...

Getting request parameters within Model in Loopback can be done by accessing the `ctx`

common/models/event.json { "name": "Event", "mongodb": { "collection": "event" }, "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "http": { "path": "organizer/:organizer_id/events" }, "properties": {}, "va ...

Applying Global Headers in NextJS SSR with getServerSideProps

I'm working on a project that utilizes NextJS with SSR requests using Axios within getServerSideProps. I'm curious if there is a method to intercept all Axios SSR requests and universally include the header: { "X-FOO": "BAR" ...

If you click outside of a Div element, the Div element will close

I am looking for a way to implement a function that will hide a specific div when I click outside of its area. The div is initially set to Position: none and can be made visible using the following function: Div Element: <div id="TopBarBoxInfo1" oncli ...

Interactive font-awesome icons within an interactive dropdown menu

I am currently facing an issue with using two Fontawesome icons in a clickable dropdown menu. The dropdown menu does not toggle when I click on the icons directly; however, it works when I click on the padding around them. The example provided by W3schools ...

Are there any instances of a race condition present in the following?

In the express server code snippet provided, there is a common object that is being manipulated in three different RESTful endpoints. Given that all HTTP requests in Node.js are asynchronous, it's possible to have simultaneous PUT and GET requests occ ...

I'm having trouble getting the Tanstack/react-query library to function properly within my Vercel application

Exploring the packaging and troubleshooting process... "@tanstack/react-query": "^5.14.2", "@tanstack/react-query-devtools": "^5.14.2", "next": "^13.5.6", "react": "18.2.0", & ...

Steps for organizing an array based on unique requirements

My goal is to retrieve an array that consists of the first and second objects based on the "point" property of each object I have a specific condition where if it is satisfied, the positions will be swapped. Default: ENGLISH[0] ENGLISH[1] MATH[0] MATH[1] ...

The NextJS homepage and API endpoint are combined on a single page

In my Next.js application, I have multiple pages and I want the component loaded at http://localhost:3000/someEndpoint to be exactly the same as the one loaded at http://localhost:3000/ I have already created an index.js file, but I am unsure how to creat ...

Switch out 2 Bootstrap columns for 2 concealed columns with just a click. Utilizing Rails 4 and Bootstrap

Using Twitter Bootstrap 3 for a column system showcasing four similar advertisements at the bottom of the page. Code Snippet: <div class="row similar"> <% @recomended_ads.each do |advertisement| %> <div class="col- ...

Unable to insert HTML code into a div upon clicking an image button

I am in the process of developing a website dedicated to radio streams, and I was advised to utilize Jquery and AJAX for loading HTML files into a div upon button click. This way, users wouldn't have to load an entirely new page for each radio stream. ...

Ways to retrieve information from an Ajax post method call using an index similar to an array

My code doesn't seem to be working in the success function of my AJAX call. I suspect there might be an issue with how I'm specifying tr and td elements. Can someone help me identify where the problem might be? $(document).ready(function () { ...

jQuery's find method returns a null value

During my Ajax POST request, I encountered an issue where I wanted to replace the current div with the one received from a successful Ajax call: var dom; var target; $.ajax({ type: "POST", url: "http://127.0.0.1/participants", data: "actio ...

What's the best way to vertically center text in a div with overflow hidden?

In my ASP GridView, I am trying to display a table with a fixed number of lines in each TD element. To achieve this, I have decided to place a div inside each TD so that I can customize the height and layout. table.XDataGridView td div.inner-table-div { h ...

"Have you ever wondered how the router object in express.js is seamlessly integrated with app.use(), considering that it only accepts

I am curious about the process of how the router object in express.js is passed to app.use(), which typically only accepts callbacks. Since router is an object of express, I am trying to understand why app.use() does not throw an error even though it req ...

Guide to building a multi-dimensional array from a flat object

My endpoint is outputting data in a specific format: const result = [ {id: 4, parentId: null, name: 'Fruits & Veggies'}, {id: 12, parentId: 133, name: 'Sanguinello'}, {id: 3, parentId: 4, name: 'Fruits'}, {id: 67, ...

Issue with element alignment using CSS increments

I'm confident that this code should be functioning properly, but for some reason it's not. I feel like there must be a small detail that I'm overlooking: Markup: <section id="content"></section> Styling: #content { positi ...

When the 'keyup' event is detected, trigger the function only on keyup

Looking for assistance in setting this to only trigger on keyup events. Can anyone provide guidance? $(function() { $('#acf-field_5a32085c7df98-field_5a3208f87df99').on('keyup', function() { $('#link-headline-fb').text($( ...