简体   繁体   English

具有恒定DOM操作的Drag / Touchmove事件

[英]Drag/Touchmove Event with constant DOM Manipulation

I am looking to implement some Mobile Components using native Javascript and AngularJS. 我希望使用本机Javascript和AngularJS实现一些移动组件。

While, I was working on creating a Pull To Refresh directive for AngularJS, I used touchmove event on a UL list. 在我为AngularJS创建Pull To Refresh指令时,我在UL列表上使用了touchmove事件。 I was trying to pull a hidden div on top of a list with custom models to show status message. 我试图将隐藏的div拉到具有自定义模型的列表顶部以显示状态消息。

I used touchmove event on the UL to create an effect of pulling by changing CSS3 translate property for the div. 我在UL上使用touchmove事件,通过更改div的CSS3 translation属性来创建拉动效果。 I was facing issue that the transition was happening after I finish touching the screen but not while I was dragging my touch. 我遇到的问题是过渡是在我完成触摸屏幕后发生的,而不是在拖动触摸时发生的。

Please help and throw in more details about the touchmove event. 请帮助并提供有关touchmove事件的更多详细信息。

Touch events 触摸事件

First of all, if you work on mobile devices and know a little about javascript you should write your own functions for the specific things that you need.So don't use libraries like angular, jquery or whatever ... it's only performance loss. 首先,如果您在移动设备上工作并且对javascript有所了解,则应该针对所需的特定功能编写自己的函数,因此请勿使用诸如angular,jquery之类的库...这仅仅是性能损失。

all you need is: 所有你需要的是:

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

& to test: & 去测试:

 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

css CSS

Use translate3d() as it activates the gpu hardware acceleration. 使用translate3d()激活gpu硬件加速。 not just translate() 不只是translate()


As your question is not very specific i can't add more info right now but... 由于您的问题不是很具体,我现在无法添加更多信息,但是...

Here are some examples using touch/mousemoves they may help you 以下是一些使用触摸/鼠标移动的示例,它们可能会对您有所帮助

Swipe & fastclick 滑动并快速点击

http://jsfiddle.net/uRFcN/ http://jsfiddle.net/uRFcN/

https://stackoverflow.com/a/17567696/2450730 https://stackoverflow.com/a/17567696/2450730

Radial Menu 径向菜单

http://jsfiddle.net/yX82S/ http://jsfiddle.net/yX82S/

Slider 滑块

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

Some UI elements 一些UI元素

http://cocco.freehostia.com/scripts/SnapLightMT%20v0.2%20by%20cocco%20(1).html http://cocco.freehostia.com/scripts/SnapLightMT%20v0.2%20by%20cocco%20(1).html

try to swipe the main content or mousedown drag left right. 尝试滑动主要内容,或将鼠标左键向右拖动。

code. 码。

http://cocco.freehostia.com/scripts/highlight.html http://cocco.freehostia.com/scripts/highlight.html


There is also a css trick that allows you to use the native scroll without the annoyng whole page move..So you don't have to use a library to scroll. 还有一个css技巧,可让您使用本机滚动而不烦恼整个页面的移动。因此,您不必使用库即可滚动。

css CSS

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

html HTML

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM