DIV is always in the middle of the js code

  • 2020-03-30 01:44:45
  • OfStack

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title> Sidebar ads </title> 
<style type="text/css"> 
#show { width:100px; height:80px; background:#0f0; position:fixed; _position:absolute; right:0px; top:0px;} 
</style> 
<script type="text/javascript"> 
window.onscroll = window.onresize = window.onload = function(){ 

var oDiv = document.getElementById("show"); 
var sTop = document.documentElement.scrollTop || document.body.scrollTop; 
var cHeight= document.documentElement.clientHeight || document.body.clientHeight; 
var mid = (cHeight - oDiv.offsetHeight) / 2; 
// oDiv.style.top = parseInt(sTop + mid) + "px"; // In theory, we should just put this sentence in the middle  

//In fact, the major browsers only recognize the following if judgment
if(navigator.appVersion.indexOf("MSIE 6")> -1){ 
oDiv.style.top = parseInt(sTop + mid) + "px"; 
}else{ 
oDiv.style.top =mid + "px"; 
} 
} 

Related articles: