简体   繁体   English

在移动设备jQuery Touch上以随机顺序选择div

[英]On Mobile device jQuery Touch select div's in random order

On Mobile device I want to select specific div wrt touch ie. 在移动设备上,我想选择特定的div wrt touch即。 when user touch on first div and touchmove to 3rd div then these both div's need to be selected. 当用户触摸first div并触摸touchmove3rd div touchmove ,则需要选择这两个格。 Like vise the order can be random 1 3 2 4, 1 2 3 4 像老虎钳一样,顺序可以是随机的1 3 2 4,1 2 3 4

The attached image will give better understanding 所附图片将使您更好地理解

1 3 2 Selection 1 3 2选择

1 3 2选择

1 2 3 selection 1 2 3选择

在此处输入图片说明

I have also created jsfiddle for the same with what I have done till. 我还为我完成了同样的工作而创建了jsfiddle You can check it at jsfiddle . 您可以在jsfiddle上进行检查。 I am using jquery mobile also trying to use touch and touchmove events but it's not working as per my requirement. 我正在使用jquery mobile并尝试使用touchtouchmove事件,但是按我的要求它不起作用。

Please help me in this, Thanks 请帮助我,谢谢

Its not really clear (for me) what you want. (对我而言)您想要的不是很清楚。 Here is a really simple attempt for you which maybe will help your self to solve your issue. 这是一个非常简单的尝试,可能会帮助您自己解决问题。

Checkout this Snippet 检出此代码段

EDIT: Updated, now works also which (v)touchmove 编辑:更新,现在也可以使用(v)touchmove

 $(function() { $(".section").on('vclick', function(e) { $('.logs').html('eventType: ' + e.originalEvent.type); $(this).addClass('green'); toHighlightElements($(this), $(".section")); }) $(".sections-wrapper").on('vmousemove', function(e) { $('.logs').html('eventType: ' + e.originalEvent.type); var $target; if(e.originalEvent.type === 'touchmove') { e.preventDefault(); $target = getActiveElement($(".section"), e.clientX, e.clientY); if(typeof $target === 'undefined') { return; } } else { $target = $(e.target); } toHighlightElements($target, $(".section")); }); function toHighlightElements($current, $overall) { for (var i = 0 ; i <= $current.index() ; i++) { $overall.eq(i).addClass('green'); } } function getActiveElement($overallElements, x, y) { return $(document.elementFromPoint(x, y)); } $('.reset').click(function() { $(".section").removeClass('green'); }); }); 
 .section { width: 50px; height: 50px; border: 1px solid black; background-color: grey; } .green { background-color: green !important; } .allowLeft { float: left; } .sections-wrapper { background: red; width: 105px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"> </script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script> <div class="sections-wrapper"> <div class="section allowLeft"> 1 </div> <div class="section allowLeft"> 2 </div> <div class="section allowLeft"> 3 </div> <div class="section allowLeft"> 4 </div> <br style="clear: both" /> </div> <br><br> <button class="reset"> reset </button> <div class="logs"> </div> 

Updated also your jsfiddle: https://jsfiddle.net/m03g52ah/12/ 还更新了您的jsfiddle: https://jsfiddle.net/m03g52ah/12/ ://jsfiddle.net/m03g52ah/12/

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

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