var msg = "窗口宽度:" + window.innerHeight + "\n窗口高度:" + window.innerWidth; alert(msg );
var msg = "窗口宽度:" + document.documentElement.clientWidth + "\n窗口高度:" + document.documentElement.clientHeight; alert(msg);
var w = window.innerWidth || document.documentElement.clientWidth;
var h = window.innerHeight || document.documentElement.clientHeight;
alert("窗口宽度:" + w + "\n窗口高度:" + h);
<body>
<div id="box1"></div>
<script type="text/javascript">
var box1 = document.getElementById("box1");
// alert(box1.currentStyle["width"]); //只支持IE浏览器
// alert(window.getComputedStyle(box1, null)["height"]); //支持浏览器外的其他浏览器
alert(getStyle(box1, "backgroundColor"));
/*
为了简化书写和兼容浏览器,一般封装一个方法出来
*/
function getStyle (obj, attributeName) {
if(obj.currentStyle){ //如果存在对象,则是在ie浏览器
return obj.currentStyle[attributeName];
}else { //其他浏览器
return window.getComputedStyle(obj, null)[attributeName];
}
}
</script>
</body>
<script type="text/javascript">
window.onscroll = function () {
console.log("开始滚动...");
//跨浏览器获得滚动的距离
console.log(document.documentElement.scrollTop | document.body.scrollTop);
}
</script>
box.onclick = function(event) {
event = event || window.event;
console.log("offsetX:" + event.offsetX + " offsetY:" + event.offsetY);
console.log("screenX:" + event.screenX + " screenY:" + event.screenY);
console.log("clientX:" + event.clientX + " clientY:" + event.clientY);
console.log("pageX:" + event.pageX + " pageY: " + event.pageY);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有