将div显示到屏幕中央
来源:互联网 发布:微信公众内容采集源码 编辑:程序博客网 时间:2024/04/28 15:45
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>提示信息</title>
<script type="text/javascript">
window.onload = function() {
var div = document.getElementById("showDiv");
div.style.position= "absolute";
div.style.top = (document.documentElement.scrollTop + (document.documentElement.clientHeight -div.offsetHeight) / 2)
+ "px";
div.style.left = (document.documentElement.scrollLeft + (document.documentElement.clientWidth - div.offsetWidth) / 2)+ "px";
};
</script>
</head>
<body></body>
</html>
2、下面也可以实现,不过要去掉上面的" <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> "这行代码。
<script type="text/javascript">
window.onload = function() {
var div = document.getElementById("showDiv");
div.style.position= "absolute";
div.style.top = (document.body.scrollTop + (document.body.clientHeight -div.offsetHeight) / 2)
+ "px";
div.style.left = (document.body.scrollLeft + (document.body.clientWidth - div.offsetWidth) / 2)+ "px";
};
</script>
3、如果需要解决兼容性问题,可以使用jquery,如下:
window.onload = function() {
var div = document.getElementById("showDiv");
div.style.position= "absolute";
div.style.top = (($(document).height()-div.offsetHeight) / 2)+ "px";
div.style.left = (($(document).width() - div.offsetWidth) / 2)+ "px";
};
- 将div显示到屏幕中央
- Qt QDialog窗体显示到屏幕中央
- 屏幕中央的div
- JFrame在屏幕中央显示
- jquery始终显示DIV中央
- 将窗体设置在屏幕中央(java)
- 对话框显示在屏幕中央的代码
- jQuery 对话框(dialog)显示在屏幕中央
- [汇编] 在屏幕中央显示时钟
- VC中窗口在屏幕中央显示
- window.open窗口显示在屏幕中央
- Qt 将窗口显示在显示屏中央
- 将项目发布到Maven中央库
- 将项目发布到Maven中央库
- div屏幕居中显示
- MessageBox(...), 只能让它显示在屏幕的中央, 能不能显示在一个Form的中央???
- 将屏幕分为4个DIV 点击某一个div时 全屏显示
- 利用CBitmap将图像快速显示到屏幕上
- NYOJ506 洗澡
- 将数据库树结构生成json串
- C++ 输入输出流的引用调用
- bat文件常用命令
- detached entity passed to persist 异常
- 将div显示到屏幕中央
- 给DIV添加滚动条
- scrollLeft,scrollWidth,clientWidth,offsetWidth
- Android 学习笔记
- Jquery获取select,dropdownlist,checkbox下拉列表框的值
- Linux下date命令,格式化输出,时间设置
- SSH配置文件
- 创建mysql数据库时指定编码
- ajax处理返回的json数据