jquery创建水平居中垂直居中弹出框
2017-02-13 16:09
381 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
#login{
width: 300px;
height: 300px;
border: 1px solid red;
position: absolute;
}
#close{
position: absolute;
right: 5px;
top: 5px;
}
</style>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
$(function(){
$('#btn').on('click',function(){
var oContent=$('<div id="login"><p>用户名:<input type="text"/></p><p>密码:<input type="text" /></p><div id="close">X</div></div>');
$('body').append(oContent);
oContent.css('left',($(wind
4000
ow).width()-oContent.outerWidth())/2);
oContent.css('top',($(window).height()-oContent.outerHeight())/2);
$('#close').on('click',function(){
oContent.remove();
})
$(window).on('resize scroll',function(){
oContent.css('left',($(window).width()-oContent.outerWidth())/2);
oContent.css('top',($(window).height()-oContent.outerHeight())/2+$(window).scrollTop());
})
})
})
</script>
</head>
<body style="height: 800px;">
<input type="button" value="点击" id="btn" />
<!--<div id="login">
<p>用户名:<input type="text"/></p>
<p>密码:<input type="text" /></p>
<div id="close">X</div>
</div>-->
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
#login{
width: 300px;
height: 300px;
border: 1px solid red;
position: absolute;
}
#close{
position: absolute;
right: 5px;
top: 5px;
}
</style>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
$(function(){
$('#btn').on('click',function(){
var oContent=$('<div id="login"><p>用户名:<input type="text"/></p><p>密码:<input type="text" /></p><div id="close">X</div></div>');
$('body').append(oContent);
oContent.css('left',($(wind
4000
ow).width()-oContent.outerWidth())/2);
oContent.css('top',($(window).height()-oContent.outerHeight())/2);
$('#close').on('click',function(){
oContent.remove();
})
$(window).on('resize scroll',function(){
oContent.css('left',($(window).width()-oContent.outerWidth())/2);
oContent.css('top',($(window).height()-oContent.outerHeight())/2+$(window).scrollTop());
})
})
})
</script>
</head>
<body style="height: 800px;">
<input type="button" value="点击" id="btn" />
<!--<div id="login">
<p>用户名:<input type="text"/></p>
<p>密码:<input type="text" /></p>
<div id="close">X</div>
</div>-->
</body>
</html>
相关文章推荐
- jQuery实现大图轮播
- jQuery轮播图(手动点击轮播)
- jQuery实现大图轮播
- jquery中attr和prop的区别
- 一行jQuery代码搞定checkbox 全选和全不选
- AMD异步模块定义介绍和Require.js中使用jQuery及jQuery插件的方法
- jquery 绘图工具 flot 学习笔记
- jquery操作cookie
- jQuery Ajax全解析
- jquery中remove()与detach()的区别
- Jquery each方法,call方法
- jQuery中 bind的用法简单介绍
- jQuery中 wrap() wrapAll() 与 wrapInner()的区别
- jQuery.extend 函数详解
- jquery bind用法
- JQuery环境搭建
- HTML5 自定义属性 data-* 和 jQuery.data 详解
- jquery实现轮播图效果
- jQuery中常用的元素查找方法总结
- jQuery中常用的元素查找方法总结