手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >DIV始终居中的js代码
DIV始终居中的js代码
摘要:复制代码代码如下:侧边栏广告#show{width:100px;height:80px;background:#0f0;position:f...

复制代码 代码如下:

<!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>侧边栏广告</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"; //理论上应该只设这句就可以居中吧

//实际上的 各大浏览器只认识下面这if判断

if(navigator.appVersion.indexOf("MSIE 6")> -1){

oDiv.style.top = parseInt(sTop + mid) + "px";

}else{

oDiv.style.top =mid + "px";

}

}

【DIV始终居中的js代码】相关文章:

精确到分钟的js日历控件,日期选择器代码

Ctrl + Enter提交前检测的代码

将HTML自动转为JS代码

发现的以前不知道的函数

你一定会收藏的Nodejs代码片段

网页里控制图片大小的相关代码

让插入到 innerHTML 中的 script 跑起来的实现代码

介绍JavaScript中Math.abs()方法的使用

一些很实用且必用的小脚本代码第1/5页

获得当前页面URL地址的三个JS代码

精品推荐
分类导航