Consistent manipulation of the DOM through the Drag/Touchmove event

Seeking to incorporate Mobile Components through native Javascript and AngularJS.

During my work on developing a Pull To Refresh directive for AngularJS, I utilized the touchmove event on a UL list. The goal was to pull a concealed div over a list with customized models to display a status message.

I employed the touchmove event on the UL to create a pulling effect by altering the CSS3 translate property for the div. Encountered an issue where the transition occurred only after releasing the touch instead of while dragging it.

Any assistance and additional insights regarding the touchmove event would be greatly appreciated.

Answer №1

Optimizing Touch Events for Mobile

When working on mobile devices, it is beneficial to write your own functions for specific tasks instead of relying on libraries like Angular or jQuery, as they can lead to performance issues.

All you really need are these event listeners:

 document.addEventListener('touchstart', ts, false);
 document.addEventListener('touchmove', tm, false);
 document.addEventListener('touchend', te, false);

To test the functionality, add these mouse event listeners as well:

 document.addEventListener('mousedown', ts, false); // set mouseIsDown to true
 document.addEventListener('mousemove', tm, false); // check if mouse is down
 document.addEventListener('mouseup', te, false); // set mouseIsDown to false

Improving CSS Performance

Utilize translate3d() in CSS, as it triggers hardware acceleration on the GPU, enhancing performance over using translate().


While your question lacks specificity at the moment, here are some touch/mouse movement examples that may be helpful:

Swipe & fastclick

http://jsfiddle.net/uRFcN/

Radial Menu

http://jsfiddle.net/yX82S/

Slider

http://jsfiddle.net/LxX34/11/

Some UI elements

Feel free to try swiping the main content or dragging left and right with a mousedown action.

For detailed code samples, visit:


Additionally, there's a CSS trick that enables native scrolling without affecting the entire page layout, eliminating the need for external libraries:

CSS

.scrollable {
    -webkit-overflow-scrolling: touch;
}
.scrollable,
.scrollable>div {
    width: 100%;
    height: 100%;
    overflow: auto;
}
.scrollable>div>div {
    min-height: 101%;
}

HTML

<div class="scrollable"><div><div></div></div></div>

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

Issue with swal() not triggering in Internet Explorer 11

Looking for some assistance here, I believe I might be missing a small detail. The _layout.cshtml file includes all the necessary scripts to ensure that sweetheart works on IE: (this used to work in previous versions, but we haven't had to support I ...

Ajax seems to be interacting with an empty session variable

I am facing some issues with a piece of code that I've written. Here's the function in question from my PHP class: public function generalSettings(){ $totalPrice = 0; foreach($_SESSION['items'] as $key => $value){ ...

`Implementing a dynamic list with image and button using Bootstrap 5`

I've been exploring ways to create a container with 4 images aligned next to each other, accompanied by a button beneath each image. My goal is for the layout to be responsive, meaning that as the screen size adjusts, the elements inside should also a ...

Is it possible to display a thumbnail image in a separate full-sized window by using CSS or JavaScript?

I am currently utilizing a program called WebWorks 2020.1 that automatically creates <img> tags from my FrameMaker source input when published to DHTML. Unfortunately, I do not have the ability to directly modify the HTML <img> or <a> tag ...

<fieldset> triggering onChange event in React form

I am facing an issue with my React component where multiple onChange functions are not getting fired. After some debugging, I realized that the problem lies with the fieldset element within the form. Removing the fieldset allows all onChange functions to w ...

Can anyone help me figure out the best way to test for observable errors in Angular2?

I'm currently working on creating unit test cases for my Angular2 components. Up until now, the test cases have been running smoothly. However, I've run into some issues with my asynchronous calls. For example, I have a method for creating a n ...

Encountering a Syntax Error within the ng-click function of a button in AngularJS

I'm currently developing a mobile-based web application using angular js along with onsen ui. I've created a follow button on the user's profile page, allowing users to follow each other. However, when the user's profile loads and the a ...

What is the best javascript framework to pair with twitter bootstrap?

After dabbling in twitter bootstrap, I discovered its impressive array of UI components. Interested in incorporating it into a project, my quest for a compatible javascript framework has left me torn between angularjs, backbonejs, and emberjs. Although I ...

Align the responsive image in the center of a container

I am facing a challenge in centering an image wrapped by an anchor tag inside a div. I have tried using display flexbox and justify-content:center for the image, which works to some extent. However, the height of the image remains constant while the width ...

Executing polymorphism in Javascript without the use of OOP classes

In JavaScript or other object-oriented programming languages, polymorphism is achieved by creating different types. For instance: class Field {...} class DropdownField extends Field { getValue() { //implementation .... } } Imagine a library f ...

Arranging Cards in Layers on Smaller Screens Using Bootstrap Framework

My row of cards in various sizes looks good on larger screens like this: https://i.sstatic.net/1qF53.png However, on smaller screens, the cards lose their appeal. https://i.sstatic.net/o1NS8.png To improve this, I want to stack the cards so that the ke ...

Dynamic Mat-select-trigger that automatically adjusts its size to fit the content

Currently, I am experimenting with an Angular Mat-Select that allows multiple selections. To display the selected values in the value field, I have implemented a custom Mat-Select-Trigger. My goal is to enable automatic resizing of the value field (similar ...

What is the reason behind having to restart the npm server each time?

When first learning Reactjs with VSCode, there was no need to restart the server after making modifications. However, now I find that I must restart the server every time I make a change in order for those changes to be applied. ...

Intensive analysis of objects comparing their characteristics

Currently delving into the world of Javascript, I encountered a coding exercise involving a "deepEqual" function that I attempted to write but ultimately struggled with. Even after reviewing the solution, one particular part perplexed me - the for loop, ...

Angular Material Flex is not providing the correct size

There seems to be a problem with certain values for setting the flex property in the Angular Material layout library. The issue is clearly demonstrated in this straightforward example. By clicking through, you can observe that some values display correctl ...

The failure within the internal request resulted in the failure of the main request

I develop a Jquery Promise with the following structure: request1() .then(response => {}) .then( () => { request2().done(response => {}) } .fail(err => {}); In the done and fail blocks, I implement code to "unblock" the scre ...

The valueChanges event of a Reactive Form is activated whenever options from a datalist are selected

Whenever a user types into the input field, I am making an API call to retrieve and display data in a datalist for autocompletion (typeahead). control.get('city').valueChanges.pipe( map((searchText) => searchText.trim().toLowerCase()), fi ...

What is the best way to create TypeScript declarations for both commonjs modules and global variables?

Wanting to make my TypeScript project compatible with both the commonjs module system and globals without modules. I'm considering using webpack for bundling and publishing it into the global namespace, but running into issues with the definitions (.d ...

Developing a transparent "cutout" within a colored container using CSS in React Native (Layout design for a QR code scanner)

I'm currently utilizing react-native-camera for QR scanning, which is functioning properly. However, I want to implement a white screen with opacity above the camera, with a blank square in the middle to indicate where the user should scan the QR code ...

Tips for adjusting column spacing in HighCharts

Looking for some advice on how to make a chart container scrollable and properly space the labels and bars within a parent container with fixed width and height. The goal is to ensure all labels are visible and bars are well spaced. Any suggestions or tips ...