首页 > 移动平台 > 详细

手机端js模拟长按事件(代码仿照jQuery)

时间:2015-02-05 17:55:37      阅读:1545      评论:0      收藏:0      [点我收藏+]

代码编写:

$.fn.longPress = function(fn) {
	var timeout = undefined;
	var $this = this;
	for(var i = 0;i<$this.length;i++){
		$this[i].addEventListener(‘touchstart‘, function(event) {
			timeout = setTimeout(fn, 800);
			}, false);
		$this[i].addEventListener(‘touchend‘, function(event) {
			clearTimeout(timeout);
			}, false);
	}
}

代码使用:

$(select).longPress(function(){
	alert(1);
});

  

手机端js模拟长按事件(代码仿照jQuery)

原文:http://www.cnblogs.com/Silababy/p/4275240.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!