首页 > 代码库 > sss
sss
function handleTouchEvent(event) {
if (event.touches.length == 1) {
var output = document.getElementById("output");
switch (event.type) {
case "touchstart":
output.innerHTML = "Touch started (" + event.touches[0].clientX + "," + event.touches[0].clientY + ")";
break;
case "touchend":
output.innerHTML = "Touch ended (" + event.changedTouches[0].clientX + "," + event.changedTouches[0].clientY + ")";
break;
case "touchmove":
event.preventDefault();
output.innerHTML = "Touch started (" + event.changedTouches[0].clientX + "," + event.changedTouches[0].clientY + ")";
break;
default:
// statements_def
break;
}
}
}
/*EventUtil.addHandler(document, "touchstart", handleTouchEvent);
EventUtil.addHandler(document, "touchmove", handleTouchEvent);
EventUtil.addHandler(document, "touchend", handleTouchEvent);*/
/*function handler() {
alert("Clicked!");
}
var oBtn = document.getElementById("btn");
oBtn.addEventListener("click", handler);
*/
/*
function showMsg() {
alert("Hello");
}
var eventUtil = {
// 添加句柄
addHandler: function(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else if (element.attachEvent) {
element.attachEvent(‘on‘ + type, handler);
} else {
element[‘on‘ + type] = handler;
}
},
// 删除句柄
removeHandler: function(element, type, handler) {
if (element.removeEventListener) {
element.removeEventListener(type, handler, false);
} else if (element.detachEvent) {
element.detachEvent(‘on‘ + type, handler);
} else {
element[‘on‘ + type] = null;
}
}
}
window.onload = function() {
var btn = document.getElementById(‘btn‘);
eventUtil.addHandler(btn, ‘click‘, showMsg);
};*/
var EventUtil = {
addHandler: function(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + type, handler);
} else {
element["on" + type] = handler;
}
},
removeHandler: function(element, type, handler) {
if (element.removeEventListener) {
element.removeEventListener(type, handler, false);
} else if (element.detachEvent) {
element.detachEvent("on" + type, handler);
} else {
element["on" + type] = null;
}
},
getEvent: function(event) {
return event ? event : window.event;
},
getTarget: function(event) {
return event.target || event.srcElement;
},
preventDefault: function(event) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = http://www.mamicode.com/false;
}
},
stopPropagation: function(event) {
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubbles = true;
}
},
getRelatedTarget: function(event) {
if (event.relatedTarger) {
return event.relatedTarget;
} else if (event.toElement) {
return event.toElement;
} else if (event.fromElement) {
return event.fromElement;
} else {
return null;
}
}
};
var image = document.getElementById(‘img‘);
EventUtil.addHandler(image, "load", function(event) {
console.log(2);
/*console.log(document.body.clientWidth);
event = EventUtil.getEvent(event);
console.log(EventUtil.getTarget(event).src);*/
});
window.onload = function() {
var btn = document.getElementById(‘btn‘);
var image = document.getElementById(‘img‘);
/*EventUtil.addHandler(image, "load", function(event) {
console.log(document.body.clientWidth);
event = EventUtil.getEvent(event);
console.log(EventUtil.getTarget(event).src);
});*/
window.addEventListener(‘load‘, function() {
alert("我是来测试的");
}, false);
/*var img = document.getElementById(‘img‘)
if (!img.complete) {
img.addEventListener(‘load‘, function() {
console.log(3);
})
} else {
console.log(2);
}*/
};
sss