[英]mobile - how to create a “virtual number lock” with JS or pure CSS
I'm experienced with web development, but I'm trying to learn some mobile and I'm not entirely sure I understand how to work with touch events. 我有Web开发方面的经验,但是我正在尝试学习一些移动设备,但我不确定是否完全了解如何处理触摸事件。 I looked at some guides ( for example ), but I'm not sure how to apply it in my case.
我查看了一些指南( 例如 ),但不确定如何在我的情况下应用它。
Consider this (ignore the quality of the code, I just doodled this quickly to explain my question): 考虑一下这一点(忽略代码的质量,我只是迅速地画了一下以解释我的问题):
var span = $("span"), btns = $("button"); btns.on("click", function() { var $this = $(this), action = $this.data("action"), curVal = parseInt( span.text() ); btns.prop("disabled", false); if (action == "less") { span.text(curVal-1); if (curVal == 2) $("#less").prop("disabled", true); } else { span.text(curVal+1); if (curVal == 8) $("#more").prop("disabled", true); } });
* { font-family: sans-serif; } button { background: #eee; padding: 10px; margin: 5px; font-weight: bold; border: 1px dashed black; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="less" data-action="less" disabled="disabled"><</button> <span>1</span> <button id="more" data-action="more">></button>
I want to do that, but instead of buttons, I want it to respond to touch movement. 我想这样做,但是我希望它能响应触摸运动,而不是按钮。 ie, when you slide your fingers right it would react like clicking on the right button and vice-versa.
即,当您向右滑动手指时,其反应就像单击右按钮一样,反之亦然。 ideally, you would be able to slide back and the number would snap to your finger (sort of like a virtual number lock, like below, though horizontal)
理想情况下,您将能够向后滑动,数字会紧贴在您的手指上(有点像虚拟数字锁,如下所示,尽管是水平的)
I can measure the movement with touchmove
and try to sync it visually but that seems like it would take ages and be a bugstrosity. 我可以通过
touchmove
来测量运动,并尝试在视觉上进行同步,但这似乎需要花费很多时间并且是一个错误。 Is there a better\\simpler way? 有没有更好更好的方法? (related: is there a way to do this with pure CSS?)
(相关:有没有办法用纯CSS做到这一点?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.