目前我正在测试这个 Zepto Mobile Javascript 框架。
我下载了示例,但奇怪的是,我注意到在 chrome 桌面浏览器上,单击触发子菜单的项目(通过 webkit 幻灯片效果)不起作用。
我在我的托管服务器上上传了相同的文件,并在我的 iphone 上测试了相同的页面,它工作得很好。
我检查了代码并注意到 Zepto 正在绑定一个 touchstart 事件,我认为它在桌面浏览器上不起作用。
$(document).ready(function(){
$(document.body).bind('touchstart', function(e){
var now = Date.now(), delta = now - (touch.last || now);
touch.target = parentIfText(e.touches[0].target);
touchTimeout && clearTimeout(touchTimeout);
touch.x1 = e.touches[0].pageX;
touch.y1 = e.touches[0].pageY;
if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
touch.last = now;
}).bind('touchmove', function(e){
touch.x2 = e.touches[0].pageX;
touch.y2 = e.touches[0].pageY;
}).bind('touchend', function(e){
if (touch.isDoubleTap) {
$(touch.target).trigger('doubleTap');
touch = {};
} else if (touch.x2 > 0 || touch.y2 > 0) {
(Math.abs(touch.x1 - touch.x2) > 30 || Math.abs(touch.y1 - touch.y2) > 30) &&
$(touch.target).trigger('swipe') &&
$(touch.target).trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)));
touch.x1 = touch.x2 = touch.y1 = touch.y2 = touch.last = 0;
} else if ('last' in touch) {
touchTimeout = setTimeout(function(){
touchTimeout = null;
$(touch.target).trigger('tap')
touch = {};
}, 250);
}
});
});
有没有人在 Chrome/Safari 上测试过 Zepto(Iphone 示例)并且他可以设法访问子菜单?
这是示例 URL - https://github.com/madrobby/zepto/blob/master/examples/iphone/index.html
Zepto 演示包 URL - https://github.com/madrobby/zepto
谢谢