1. 事件对象的获取
var event = event || window.event; // 兼容写法, ie678中支持window.event
2. event事件重要内容
event.png3. screenX、pageX、clientX的区别:
qubie.png3. 获取屏幕可视区域的宽高
function client(){
if(window.innerHeight !== undefined){
return {
"width": window.innerWidth,
"height": window.innerHeight
}
}else if(document.compatMode === "CSS1Compat"){
return {
"width": document.documentElement.clientWidth,
"height": document.documentElement.clientHeight
}
}else{
return {
"width": document.body.clientWidth,
"height": document.body.clientHeight
}
}
}
// 阻止冒泡
event = event || window.event;
if(event && event.stopPropagation){
event.stopPropagation();
}else{
event.cancelBubble = true; // IE10以下
}
// 获取目标元素的兼容写法:
var obj = event.target ? event.target : event.srcElement;
网友评论