二、 整个浏览器可视区域的碰壁反弹
margin:0;
padding:0;
}
#bounce{
height: 50px;
width: 50px;
border-radius: 50%;/*background: yellow;*/position: absolute;
left:0;
top:0;
}
//获取元素
var container = gt("con");//小球所在容器
var bounce = gt("bounce");//反弹的小球
//设置小球随机背景颜色
bounce.style.background =ranColor();//获取小球在可视区域的滚动范围
//获取可视区域的宽高(不含任务栏)
var aWidth = document.documentElement.clientWidth || document.body.clientWidth ||window.innerWidth;var aHeight = document.documentElement.clientHeight || document.body.clientHeight ||window.innerHeight;
console.log("可视区域不含任务栏的范围:w:"+aWidth + "===h:"+aHeight);//减去小球的宽高即为活动范围,此处不加单位,方便moveDistance()方法内if条件判断
var scrollMaxX = (aWidth -bounce.offsetWidt