Zepto 移动框架 - 浏览器中的事件
目前我正在测试这个 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
谢谢
At the moment I am testing this Zepto Mobile Javascript framework.
I downloaded the examples but strangely enough I am noticing that on chrome desktop browser, when clicking on the item that triggers a sub menu (by a webkit slide effect) is not working.
I uploaded the same files on my hosting server and tested out the same page on my iphone it works perfectly fine.
I checked the code and noticed that Zepto is doing binding of a touchstart event where I think it does not work on a desktop browser.
$(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);
}
});
});
Does anyone tested Zepto (Iphone Example) on Chrome/Safari and he can managed to access the submenu?
This is the example URL - https://github.com/madrobby/zepto/blob/master/examples/iphone/index.html
Zepto Demo Package URL -
https://github.com/madrobby/zepto
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
触摸事件和点击事件是有区别的。触摸事件在桌面浏览器中不起作用,但在移动客户端上要快得多,而点击事件对于桌面浏览器更好。您应该相应地使用它们。
There is a difference between touch and click events. Touch events will not work in a desktop browser, but are much faster on mobile clients, whereas clicks are better for desktop browsers. You should use them accordingly.