브라우저를 기준으로 DIV 고정 위치 변경하기

2483 단어 브라우저

 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>
	<head>
		<title>Anchor Properties</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta content="noindex, nofollow" name="robots">
		<script>
function top(){
	window.scrollTo(0,0);
}		
		
function bottom(){
	//scrollHeight            。
	window.scrollTo(0,document.body.scrollHeight);
}

function left(){	
	//alert("left");alert(document.body.scrollLeft)
	var left = 0-document.body.scrollWidth;//       
	window.scrollBy(left,0 );
}

function right(){
	//alert(document.body.scrollWidth);
	//        
	window.scrollBy(document.body.scrollWidth,0);
}		

function init(){
	var init_pos=oLayer.style.posTop ;
	var init_left=oLayer.style.posLeft;
	
	document.body.onscroll=function(){ 
	//document.body.scrollTop                  
		oLayer.style.posTop=document.body.scrollTop+init_pos;
	//scrollLeft                               
		oLayer.style.posLeft=document.body.scrollLeft +init_left;
	}
}		
		
		
		</script>
	</head>
	<body onload="init()">
	<a onclick="bottom()">  </a>
	<div id="oLayer" style="position:absolute;left:120;top:60;z-index:2;background:green;width:120px;height:120px"> ddddd
</div> 

	<br>
	<a onclick="right()"> &nbsp; </a>
	<div style="width:1500px;height:30px;float:left">width="2000px"</div>
	<a style="float:right" onclick="left()"> &nbsp; </a>
	<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><a onclick="top()"> &nbsp; </a>
	</body>
</html>



좋은 웹페이지 즐겨찾기