GithubHelp home page GithubHelp logo

longtap's Introduction

移动端页面功能扩展-----长按事件

有事在做移动端页面开发的过程中遇到这种需求:“模拟指纹识别”。 实际上我们只能通过长按页面中的元素来模拟这个功能。 在jQuery和Zepto中都没有包含长按事件,所以需要我们来来扩展一下。

$.fn.longTap = function(fn) {
	var timeout = undefined;
	var $this = this;
	for(var i = 0;i < $this.length; i += 1){
		$this[i].addEventListener('touchstart', function(event) {
			timeout = setTimeout(fn, 800); //长按时间超过800ms,则执行传入方法
		}, false);
		$this[i].addEventListener('touchend', function(event) {
			clearTimeout(timeout); //长按事件少于800ms,不会执行传入的方法
		}, false);
	}
};

首先要添加这段代码,然后调用:

$('body').longTap(function(){
	alert('长按');
});

longtap's People

Contributors

yu-bo-yang avatar

Watchers

James Cloos avatar smileyby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.