Tips for customizing a translateX based on the pan gesture in Hammer.js

I need to apply a translateX() transformation to an element while the user pans it using Hammer.js. Essentially, as the user drags the content left, I want it to move left and vice versa.

Here is my current implementation:

var manager = new Hammer.Manager(elem);

var panner = new Hammer.Pan({ direction: Hammer.DIRECTION_HORIZONTAL, threshold: 0 });

manager.add(panner);

manager.on("panleft", function(e) {
    elem.style.transform = "translateX(" + (e.distance * -1) + "px)";
});

manager.on("panright", function(e) {
    elem.style.transform = "translateX(" + e.distance + "px)";
});

The code functions properly, however, there is a glitch when the user pans left and then quickly goes back right causing negative translations. How can this be resolved?

Answer №1

My solution involved listening for the panmove event and manipulating the e.deltaX property:

manager.on("panmove", function(e) {
   elem.style.transform = "translateX(" + e.deltaX + "px)";
});

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

JSON error: Unable to access property 'xxx' as it is not defined

One way I extract an attribute value is like this: item['@attr']['nowplaying'] While this method is effective when the attribute exists within the json, it throws an error if the attribute is missing: Uncaught TypeError: Cannot read ...

Tips for integrating a template generated by webpack into Laravel

I am currently working on a Laravel project and have incorporated a third-party HTML template that utilizes webpack and Laravel mix to compile assets. Is there a way to import this HTML template into my Laravel project and have it compiled within the pro ...

Conceal when dates align

In my events list, I have dates displayed and would like to hide any end dates that are the same as the start dates. For instance; <span class="start_date">Wed 23rd January</span> <span class="end_date">Wed 23rd January</span> I ...

Encountering challenges with the angular2-infinite-scroll plugin

I encountered 2 errors while using my application: Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:3002/angular2-infinite-scroll angular2-polyfills.js:1243 Error: XHR error (404 Not Found) loading htt ...

Urgent dependency alert: calling for a necessity (sequelize) in next.js is a vital element

I'm encountering a challenge with integrating sequelize into my Next.js 13 project to connect my API routes with the database. I keep receiving errors that say "Critical dependency: the request of a dependency is an expression." import * as pg from &a ...

Encountering an error while submitting form via Ajax to PHP backend

Currently, I am in the process of developing a form that solicits information from a user, including their name, address, amount1, amount2, and a comment. It seems that the radio inputs for amount1 and amount2 are causing issues with my form. Upon submiss ...

Oops! An issue occurred while creating a pass with the Google Wallet API

I'm currently following the instructions provided at this guide to set up my Google Wallet Pass Generic passes. After generating the payload for my JWT, I encountered an error each time I attempted to test it in Google Wallet. The error message shown ...

What is the best way to center text both vertically and horizontally within a container using Bootstrap 4?

To achieve a centered alignment for the h1 and p elements within the division, follow the code snippet below: <div id="outer" class="container"> <div id="inner"> <h1>Heading</h1> <p>Some content</p> </div> ...

The alignment and sizing issues with stacking icons using fontawesome are still unresolved

I have been exploring the use of stacked icons with fontawesome, following a helpful blog post by Dave Gandy. Although stacking is working well, I am facing an issue aligning a stacked icon with a non-stacked icon (which is fa-5x). It's challenging t ...

Toggle visibility of the last cell in a nested table by clicking on the first cell in each row of the table

I am looking to create a nested table structure for displaying data, as shown in the following link. Below is the code I have implemented in grid view in asp.net, but now I am attempting to implement it in HTML. The issue at hand: When clicking on the ...

Unit test: Passing a deeply nested object as a prop to a React component

My functional component looks like this: const ImageScreen = (props: any) => { const images: object[] = []; props.navigation.state.params.images.forEach((image: any) => //some code ); return ( <View style={CommonStyles.normalPage} ...

Redirecting in Next.js from an API route

I am in the process of developing a backend application that necessitates user authentication. Within this project, I'm utilizing 2 external APIs: API A: responsible for managing user accounts and sessions API B: utilized for executing CRUD operation ...

Unable to resize images in Firefox

Why is it that resizing doesn't seem to work in Firefox but functions fine in Internet Explorer? I'm struggling to find a way to make it consistent across all browsers. My goal is to resize the width to 800 and height to 475, disable maximizing t ...

Using Angular's UI Typeahead feature in conjunction with the `$http.get`

Seeking assistance with retrieving data from a local server using JSON (not JSONP) and presenting it in a typeahead via Angular UI bootstrap and Angular. Successfully implemented timeout() and jsonp based on examples found, confirming that promises are fun ...

The Bootstrap navbar collapse feature is malfunctioning

My navigation bar is not functioning correctly with Bootstrap 5. I have all the necessary CSS and JavaScript files included in my HTML, but when I try to toggle the navbar, the dropdown menu does not appear. I have checked my code multiple times and it a ...

Removing the empty option from Angular

I am encountering an issue with an empty option when cycling through an array. Below is the code snippet. View: <select ng-model="getseason" class="form-control"> <option ng-repeat="season in seasons" value="{{ season }}"> Seas ...

Struggling to incorporate a basic drop-down into my design despite implementing transitions

Looking to optimize space on a webpage, I am interested in creating a hover effect for topics that reveals sub-topics with a smooth ease-out animation. Here is an example of the effect I am aiming for: https://jsfiddle.net/170z6pj1/ I have been strugglin ...

Determining the current directory and file name in React and Webpack

Currently, I am working on a react js project and utilizing webpack and redux. Below is the organization of folders in my project: -assets -src -component -index.jsx -container -index.jsx My goal is to assign dynamic className to the inde ...

"Trouble with server communication: data array not being passed to hbs

In my GET route, I have the following: app.get(("/employee/:id"), (req, res) => { data.getEmployeeByNum(req.params.id).then((data) => { res.render("employee", {employee: data}); }).catch(function(reason) { res.render("employe ...

Encountering difficulties in transferring bulky files with the request module in Node.js

When working on a Node.js project, I encountered an issue with transferring files from the computer to the server. While I am able to successfully send files that are up to 2mb in size, larger files fail to upload. Here is the code snippet I am using: var ...