Javascript 如何改进移动浏览器的拖放功能?
我正在尝试使用javascript实现类似Tinder应用程序的拖放效果 通过chrome调试器工具在chrome mobile emulator上进行监控效果很好,但当我尝试在真正的移动设备nexus 5上运行时,chrome mobile的监控效果非常差 这是我的密码: JavascriptJavascript 如何改进移动浏览器的拖放功能?,javascript,jquery,touch,Javascript,Jquery,Touch,我正在尝试使用javascript实现类似Tinder应用程序的拖放效果 通过chrome调试器工具在chrome mobile emulator上进行监控效果很好,但当我尝试在真正的移动设备nexus 5上运行时,chrome mobile的监控效果非常差 这是我的密码: Javascript $(function() { $('body').on('touchstart', function(){ $('.item').bind('touchmove',func
$(function() {
$('body').on('touchstart', function(){
$('.item').bind('touchmove',function(e){
var self = this;
var xPos = e.originalEvent.touches[0].pageX;
$(self).css({'-webkit-transform' : 'rotate('+ xPos +'deg)',
'-moz-transform' : 'rotate('+ xPos +'deg)',
'-ms-transform' : 'rotate('+ xPos +'deg)',
'transform' : 'rotate('+ xPos +'deg)',
'left' : xPos+'px'
});
// debugger
})
})
});
CSS
HTML
...
您可以缓存“body”和“.item”的选择器。这样以后就不会有任何关于DOM的旅行了
var bodyness=$('body');
var itemness=$('.item');
$(function() {
bodyness.on('touchstart', function(){
itemness.bind('touchmove',function(e){
var self = this;
var xPos = e.originalEvent.touches[0].pageX;
$(self).css({'-webkit-transform' : 'rotate('+ xPos +'deg)',
'-moz-transform' : 'rotate('+ xPos +'deg)',
'-ms-transform' : 'rotate('+ xPos +'deg)',
'transform' : 'rotate('+ xPos +'deg)',
'left' : xPos+'px'
});
// debugger
})
})
});
</head>
<body>
<div class="item">
Item
</div>
<div class="data"></div>
</body>
</html>
var bodyness=$('body');
var itemness=$('.item');
$(function() {
bodyness.on('touchstart', function(){
itemness.bind('touchmove',function(e){
var self = this;
var xPos = e.originalEvent.touches[0].pageX;
$(self).css({'-webkit-transform' : 'rotate('+ xPos +'deg)',
'-moz-transform' : 'rotate('+ xPos +'deg)',
'-ms-transform' : 'rotate('+ xPos +'deg)',
'transform' : 'rotate('+ xPos +'deg)',
'left' : xPos+'px'
});
// debugger
})
})
});