居中
来源:互联网 发布:乐视没有mac版怎么看4K 编辑:程序博客网 时间:2024/05/01 05:00
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $(obj).height();
var popupWidth = $(obj).width();
$(obj).css({
"position": "absolute",
"top": (windowHeight-popupHeight)/2+$(document).scrollTop(),
"left": (windowWidth-popupWidth)/2
});
}
//滚动的时候自动居中
$(window).scroll(function(){
center(obj);
});
//窗口变化自动居中
$(window).resize(function(){
center(obj);
});
showDiv();
function showDiv(obj){
$(obj).show();
center(obj);
$(window).scroll(function(){
center(obj);
});
$(window).resize(function(){
center(obj);
});
}
//按回车提交
$(document).keydown(function(e){
if(e.keyCode ==13){
//要调用的方法
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery.js"></script>
<style>
.div1{width: 300px;height: 400px;background: red;}
</style>
</head>
<body>
<div class="div1"><span>居中居中</span></div>
</body>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$('.div1 span').css({
position:'absolute',
left: ($(".div1").width() - $('span').outerWidth())/2,
top: ($(".div1").height() - $('span').outerHeight())/2 + $(document).scrollTop()
});
</script>
</body>
</html>
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 水平居中,垂直居中
- 水平居中垂直居中
- div代码居中 上下居中 左右居中
- 居中(水平居中+垂直居中)
- css居中控制 水平居中 垂直居中
- css img 居中/水平居中/垂直居中
- 窗口居中
- 多Kinect高精度骨架数据读取、整合与显示技术转让
- 数据结构--树和二叉树03
- javascript 数组方法属性总结
- md5算法使用方法(写一个md5类如下,调用时只需要Encrypt.e(密码))即可
- HTTP协议
- 居中
- Windows+python安装xgboost(治理windowerror-127)
- 腾讯云配置javaweb开发环境
- spring mvc 框架介绍
- 跳舞毯
- Leetcode Week5
- Log4J的简单使用
- XAMPP Mysql 忘记root密码解决方案
- 全局变量惹的祸