tap为什么会出现闪退现象点透现象,以后还用它吗

相关个股:
相关个股:
相关个股:
相关个股:
点击排行榜
理财工具箱
你的到手工资怎么算?
税前算税后
税后反推税前
我税前工资4500元,那我社保要交多少?
46岁韩星金惠秀拍写真
猫头鹰展翅拥抱救命恩人
绝交信看得父母眼泪出来
广西暴雨公交车被淹没
萌警犬试穿新款背心
网红女主播直播看欧洲杯
揭秘新疆史上最牛夜市
救护车既拉病人又运遗体
江苏3万人狂扫30吨龙虾
航拍上海迪士尼主会场
美枪击案凶手住宅画面
中外美女胸模大赛来袭
情侣&滚床单&包粽子
女生晒大一大四对比照
名人雕像成考生许愿墙县区先锋网导航&&
市开发区:宿马园区:、、市高新区:
优秀网站链接
&-------党建网站-------
&全国农村党建网
&全国远程教育网
&共产党员网
&中国共产党新闻网
&-------市直网站-------
&宿州新闻网
&宿州人才工作网
&拂晓新闻网
&-------其它网站-------
共产党员微信订阅号二维码
安徽先锋网订阅号二维码
宿州先锋订阅号二维码
建议:使用IE6.0以上版本的浏览器、以上显示模式浏览此网站,将获得较好的效果!版权所有 Copyright@2005 宿州市委组织部&&&&协办单位:宿州市农村综合经济信息中心宿州市组织部党员电化教育中心电话:、3651120投稿信箱:技术支持:当前位置: >
zepto的tap事件的点透问题的几种解决方案
时间: 08:21
作者:imFec9
zepto的tap事件点透问题分析:
1、点透是什么
你可能碰到过在列表页面上创建一个弹出层,弹出层有个关闭的按钮,你点了这个按钮关闭弹出层后后,这个按钮正下方的内容也会执行点击事件(或打开链接)。这个被定义为这是一个点透现象。
在前面的项目中遇到了如下图的问题:在点击弹出来的选择组件的右上角完成后会让完成后面的input输入框聚焦,弹出输入键盘,也就是点透了
2、为什么会出现点透呢?这个需要从zepto(或者jqm)源码里面看关于tap的实现方法:
1 $(document).ready(function(){
var now, delta, deltaX = 0, deltaY = 0, firstTouch, _isPointerType
if ('MSGesture' in window) {
gesture = new MSGesture()
gesture.target = document.body
$(document)
.bind('MSGestureEnd', function(e){
var swipeDirectionFromVelocity =
e.velocityX
1 ? 'Right' : e.velocityX
-1 ? 'Left' : e.velocityY
1 ? 'Down' : e.velocityY
-1 ? 'Up' : null;
if (swipeDirectionFromVelocity) {
touch.el.trigger('swipe')
touch.el.trigger('swipe'+ swipeDirectionFromVelocity)
下一篇:没有了zepto的touch模块解决click延迟300ms问题以及点透问题的详解
大家都知道移动端的click事件会延迟300ms触发,这时大家可以使用zepto的touch模块,里面定义了一个tap事件,通过绑定tap事件,可以实现点击立即触发的功能。
那么,它的tap事件是怎么实现的呢?这是我们要解决的第一个问题。
第二个问题,大家都知道zepto的tap事件会有点透的问题,那么,点透如何出现,点透为什么会出现,点透问题如何解决等,这是我们要解决的第二个问题。
我们先来看tap事件是如何实现的?
查看touch.js代码,在最后的代码中有以下代码:
;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown',
'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){
$.fn[eventName] = function(callback){ return this.on(eventName, callback) }
上面的代码,是把tap函数,赋给zepto的原型对象。因此,使用tap事件处理函数,有以下两种方法:
1.$("div").tap(function(){})
2.$("div").on("tap",function(){})  
接下来,我们来查看,touch.js是如何实现tap自定义事件的。
$(document)
.bind('MSGestureEnd', function(e){
var swipeDirectionFromVelocity =
e.velocityX & 1 ? 'Right' : e.velocityX & -1 ? 'Left' : e.velocityY & 1 ? 'Down' : e.velocityY & -1 ? 'Up' :
if (swipeDirectionFromVelocity) {
touch.el.trigger('swipe')
touch.el.trigger('swipe'+ swipeDirectionFromVelocity)
.on('touchstart MSPointerDown pointerdown', function(e){
if((_isPointerType = isPointerEventType(e, 'down')) &&
!isPrimaryTouch(e)) return
firstTouch = _isPointerType ? e : e.touches[0]
if (e.touches && e.touches.length === 1 && touch.x2) {
// Clear out touch movement data if we have it sticking around
// This can occur if touchcancel doesn't fire due to preventDefault, etc.
touch.x2 = undefined
touch.y2 = undefined
now = Date.now()
delta = now - (touch.last
touch.el = $('tagName' in firstTouch.target ?
firstTouch.target : firstTouch.target.parentNode)
touchTimeout && clearTimeout(touchTimeout)
touch.x1 = firstTouch.pageX
touch.y1 = firstTouch.pageY
if (delta & 0 && delta &= 250) touch.isDoubleTap = true
touch.last = now
longTapTimeout = setTimeout(longTap, longTapDelay)
// adds the current touch contact for IE gesture recognition
if (gesture && _isPointerType) gesture.addPointer(e.pointerId);
.on('touchmove MSPointerMove pointermove', function(e){
if((_isPointerType = isPointerEventType(e, 'move')) &&
!isPrimaryTouch(e)) return
firstTouch = _isPointerType ? e : e.touches[0]
cancelLongTap()
touch.x2 = firstTouch.pageX
touch.y2 = firstTouch.pageY
deltaX += Math.abs(touch.x1 - touch.x2)
deltaY += Math.abs(touch.y1 - touch.y2)
.on('touchend MSPointerUp pointerup', function(e){
if((_isPointerType = isPointerEventType(e, 'up')) &&
!isPrimaryTouch(e)) return
cancelLongTap()
if ((touch.x2 && Math.abs(touch.x1 - touch.x2) & 30)
(touch.y2 && Math.abs(touch.y1 - touch.y2) & 30))
swipeTimeout = setTimeout(function() {
touch.el.trigger('swipe')
touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)))
touch = {}
// normal tap
else if ('last' in touch)
// don't fire tap when delta position changed by more than 30 pixels,
// for instance when moving to a point and back to origin
if (deltaX & 30 && deltaY & 30) {
// delay by one tick so we can cancel the 'tap' event if 'scroll' fires
// ('tap' fires before 'scroll')
tapTimeout = setTimeout(function() {
// trigger universal 'tap' with the option to cancelTouch()
// (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
var event = $.Event('tap')
event.cancelTouch = cancelAll
touch.el.trigger(event)
// trigger double tap immediately
if (touch.isDoubleTap) {
if (touch.el) touch.el.trigger('doubleTap')
touch = {}
// trigger single tap after 250ms of inactivity
touchTimeout = setTimeout(function(){
touchTimeout = null
if (touch.el) touch.el.trigger('singleTap')
touch = {}
touch = {}
deltaX = deltaY = 0
上面的代码,大家都知道,是在document上绑定了很多事件,其中,我们只要关注touchstart和touchend 这两个事件绑定。
在touchend的事件处理函数中,有以下代码:
tapTimeout = setTimeout(function() {
// trigger universal 'tap' with the option to cancelTouch()
// (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
var event = $.Event('tap')
event.cancelTouch = cancelAll
touch.el.trigger(event)
// trigger double tap immediately
if (touch.isDoubleTap) {
if (touch.el) touch.el.trigger('doubleTap')
touch = {}
// trigger single tap after 250ms of inactivity
touchTimeout = setTimeout(function(){
touchTimeout = null
if (touch.el) touch.el.trigger('singleTap')
touch = {}
以上代码就会立即触发一个自定义的tap事件。这时绑定的tap事件回调函数就会立即执行。
因为点击事件,就是touchstart和touchend的组合。
当touchend触发时,就代表一次点击结束,因此在touchend的回调函数中,触发一个自定义的tap事件,相当于触发了tap事件,因此马上就会执行,而不会出现click事件延迟300ms。  
大家都知道,使用zepto的tap事件,会出现点透的问题。
我们先来了解下,什么叫点透问题?
假如你在列表页面上创建一个弹出层,弹出层有个关闭的按钮(绑定了tap事件),你点了这个按钮关闭弹出层后,这个按钮正下方的内容也会执行点击事件(或打开链接)。这个就是一个&点透&现象。
点透出现的原因是:延迟300ms的click事件触发了。
zepto的touch模块中,没有对这个延迟300ms的click事件取消,或者取消不了。
而fastClick中,会对这个延迟300ms的click事件取消,也就是这个click事件不会触发。
所以zepto的tap事件(通过touchstart和touchend模拟出来的)有点透问题,而fastClick的click事件(通过touchstart和touchend模拟出来的)没有。
zepto中,没有对真实的延迟300ms的click事件做处理,或者做了处理,但是还是触发了。而fastClick对真实的延迟300ms的click事件做了处理,不会触发。
深入到zepto的touch.js和fastClick的源码,我们可以得知:
zepto的tap事件和fastClick的click事件,源码差不多。
为什么基本相同的代码,zepto会点透而fastclick不会呢?
原因是zepto的代码里面有个settimeout,在settimeout里面执行e.preventDefault()不会生效,因此zepto中的延迟300ms的click事件会触发,而fastClick不会。
解决tap点透问题:
1.使用fastclick,不过你之前写的tap事件,都要改成click事件。
2.使用基于zepto的tap插件,此插件,代码量不大,也不用修改你写的tap事件,需要的请问我要,谢谢。
> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!
目的:记录 Zepto.js touch模块 源码阅读 源码: // Zepto.js // (c)
Thomas Fuchs // Zepto.js may be freely distributed under the MIT license. ; (function($) { var touch = {}, touchTimeout ...
源码: // Zepto.js // (c)
Thomas Fuchs // Zepto.js may be freely distributed under the MIT license. ; (function($) { var touch = {}, touchTimeout, tapTimeout, swipeTimeout,
printf() 控制台输出中文显示问号,英文和数字正常,解决如下: 包含locale.h,然后在输出前加上即可解决 setlocale(LC_ALL, &CHS&); 下文转载自曲径通幽论坛:http://www.groad.net/bbs/thread-.html --------------------------- ...
手机端click事件300ms延迟问题
问题由来:双击事件 假定这么一个场景.用户在iOS Safari 里边点击了一个链接.由于用户可以进行双击缩放或者双击滚动的操作,当用户一次点击屏幕之后,浏览器并不能立刻判断用户是确实要打开这个链接,还是想要进行双击操作.因此,iOS Safari 就等待 300 毫秒,以判断用户是否再次点击了屏幕.于是就出现了3 ...
一.事件捕获与冒泡 先扯一下事件的触发流程,这个之后会用到. DOM2级事件规定事件包括三个阶段: ① 事件捕获阶段 ② 处于目标阶段 ③ 事件冒泡阶段 大概的流程就是事件从最外层一层一层往里面传递(捕获阶段), 到达触发事件的目标元素(目标阶段),然后再一层一层往上冒泡(冒泡阶段).这个流程事件所经过的元素绑定的对应事件的侦听器都会被触发.例如对元素p的子 ...
这要追溯至 2007 年初.苹果公司在发布首款 iPhone 前夕,遇到一个问题 —— 当时的网站都是为大屏幕设备所设计的.于是苹果的工程师们做了一些约定,应对 iPhone 这种小屏幕浏览桌面端站点的问题.这当中最出名的,当属双击缩放(double tap to zoom).这也是会有上述 300 毫秒延迟的主要原因. 当用户一次点击屏幕之后,浏览器并不能 ...
原文:/infodetail-822565.html 这要追溯至 2007 年初.苹果公司在发布首款 iPhone 前夕,遇到一个问题 —— 当时的网站都是为大屏幕设备所设计的.于是苹果的工程师们做了一些约定,应对 iPhone 这种小屏幕浏览桌面端站点的问题.这当中最出名的,当属双击缩放(double tap
Iptables 加载模块-解决 ./runme –download 在网上收了好多文档大该都是差不多得:但就是到了./runme –download 就也错了. 查看内核版本 uname –a Linux localhost.localdomain 2.6.18-128.el5 #1 SMP Wed Dec 17 11:42:39 EST 2008 i68 ...

我要回帖

更多关于 月食现象只会出现在 的文章

 

随机推荐