div层自动适应显示方向

function over(weather){  //weather为div的id  onmouseover事件

//var div=document.getElementById(weather);
     
weather.style.display='';


var divwidth=new Number(weather.clientWidth);    //div的宽度  
var divheight=new Number(weather.clientHeight);   //div的高度
var scrollw=document.body.scrollWidth;  //浏览器的宽度
var scrollh=document.body.scrollHeight;  //浏览器的高度


if(scrollw-event.screenX>divwidth ){
weather.style.pixelLeft=event.offsetX+10;

}
    if (scrollh-event.screenY>divheight){
weather.style.pixelTop=event.offsetY+10;

}
    if((scrollw-event.screenX)<=divwidth) {
weather.style.pixelLeft=event.offsetX-(divwidth+10);

}
    if((scrollh-event.screenY)<=divheight){
weather.style.pixelTop=event.offsetY-(divheight+10);


}
}

你可能感兴趣的:(DHTML+CSS)