toy-hammer.js
548 Bytes
// 超轻量锤子,业务代码不用动,替换掉重量级的 hammer.js
const $ = require('yoho-jquery');
const ToyHammer = function(elem) {
this.elem = elem;
};
const EVENT_MAPPER = {
tap: 'touchstart'
};
ToyHammer.prototype.on = function(event, fn) {
const mappedEvent = EVENT_MAPPER[event];
if (this.elem && mappedEvent) {
$(this.elem).on(mappedEvent, function(e) {
fn({
srcEvent: e,
target: e.target
});
});
}
};
module.exports = ToyHammer;