可以实现手势操作:拖动、缩放、旋转。封装好的脚本方法是这样的:
var cat = window.cat || {};
cat.touchjs = {
left: 0,
top: 0,
scaleVal: 1, //缩放
rotateVal: 0, //旋转
curStatus: 0, //记录当前手势的状态, 0:拖动, 1:缩放, 2:旋转
//初始化
init: function ($targetObj, callback) {
touch.on($targetObj, 'touchstart', function (ev) {
cat.touchjs.curStatus = 0;
ev.preventDefault();//阻止默认事件
});
if (!window.localStorage.cat_touchjs_data)
callback(0, 0, 1, 0);
else {
var jsonObj = JSON.parse(window.localStorage.cat_touchjs_data);
cat.touchjs.left = parseFloat(jsonObj.left), cat.touchjs.top = parseFloat(jsonObj.top), cat.touchjs.scaleVal = parseFloat(jsonObj.scale), cat.touchjs.rotateVal = parseFloat(jsonObj.rotate);
callback(cat.touchjs.left, cat.touchjs.top, cat.tou