js实现点击按钮,弹出新窗口
2016-05-31 17:59
821 查看
*js引入jquery.js
样式:
<style type="text/css">
.window{
width:800px;
background-color:#f6a828;
position:absolute;
padding:2px;
margin:5px;
display:none;
}
.content{
height:350px;
background-color:#FFF;
font-size:14px;
overflow:auto;
}
.title{
padding:2px;
color:black;
font-size:14px;
}
.title img{
float:right;
}
</style>
<script type='text/javascript'>
//获取窗口的高度
var windowHeight;
//获取窗口的宽度
var windowWidth;
//获取弹窗的宽度
var popWidth;
//获取弹窗高度
var popHeight;
function init(){
windowHeight=$(window).height();
windowWidth=$(window).width();
popHeight=$(".window").height();
popWidth=$(".window").width();
}
//关闭窗口的方法
function closeWindow(){
$(".title img").click(function(){
$(this).parent().parent().hide("slow");
});
}
//定义弹出居中窗口的方法
function popCenterWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=(windowHeight-popHeight)/2;
var popX=(windowWidth-popWidth)/2;
//alert('jihua.cnblogs.com');
//设定窗口的位置
$("#center").css("top",popY).css("left",popX).slideToggle("slow");
closeWindow();
}
function popLeftWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=windowHeight-popHeight;
//var popX=-(windowWidth-popWidth);
//alert(popY);
//设定窗口的位置
$("#left").css("top",popY-50).css("left",50).slideToggle("slow");
closeWindow();
}
function popRightWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=windowHeight-popHeight;
var popX=windowWidth-popWidth;
//alert(www.cnblogs.com/jihua);
//设定窗口的位置
$("#right").css("top",popY-50).css("left",popX-50).slideToggle("slow");
closeWindow();
}
</script>
实现方式:
$(function(){
//按钮点击事件
$("#btn_center").click(function () {
popCenterWindow();
});
});
function windowClose(){
$('#center').hide("slow"); //关闭窗口
}
//按钮
<button id="btn_center"><h1>按钮名称</h1></button>
<div class="window" id="center">
<div id="title" class="title"><img src="http://pic002.cnblogs.com/images/2012/451207/2012100814082487.jpg" alt="关闭" />标题名称</div>
<div class="content">
//弹出窗口中显示的内容
<button onclick='windowClose()'><h1>取消窗口</h1></button>
</div>
</div>
$(function(){
//按钮点击事件
$("#btn_center").click(function () {
popCenterWindow();
});
});
Songsong
样式:
<style type="text/css">
.window{
width:800px;
background-color:#f6a828;
position:absolute;
padding:2px;
margin:5px;
display:none;
}
.content{
height:350px;
background-color:#FFF;
font-size:14px;
overflow:auto;
}
.title{
padding:2px;
color:black;
font-size:14px;
}
.title img{
float:right;
}
</style>
<script type='text/javascript'>
//获取窗口的高度
var windowHeight;
//获取窗口的宽度
var windowWidth;
//获取弹窗的宽度
var popWidth;
//获取弹窗高度
var popHeight;
function init(){
windowHeight=$(window).height();
windowWidth=$(window).width();
popHeight=$(".window").height();
popWidth=$(".window").width();
}
//关闭窗口的方法
function closeWindow(){
$(".title img").click(function(){
$(this).parent().parent().hide("slow");
});
}
//定义弹出居中窗口的方法
function popCenterWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=(windowHeight-popHeight)/2;
var popX=(windowWidth-popWidth)/2;
//alert('jihua.cnblogs.com');
//设定窗口的位置
$("#center").css("top",popY).css("left",popX).slideToggle("slow");
closeWindow();
}
function popLeftWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=windowHeight-popHeight;
//var popX=-(windowWidth-popWidth);
//alert(popY);
//设定窗口的位置
$("#left").css("top",popY-50).css("left",50).slideToggle("slow");
closeWindow();
}
function popRightWindow(){
init();
//计算弹出窗口的左上角Y的偏移量
var popY=windowHeight-popHeight;
var popX=windowWidth-popWidth;
//alert(www.cnblogs.com/jihua);
//设定窗口的位置
$("#right").css("top",popY-50).css("left",popX-50).slideToggle("slow");
closeWindow();
}
</script>
实现方式:
$(function(){
//按钮点击事件
$("#btn_center").click(function () {
popCenterWindow();
});
});
function windowClose(){
$('#center').hide("slow"); //关闭窗口
}
//按钮
<button id="btn_center"><h1>按钮名称</h1></button>
<div class="window" id="center">
<div id="title" class="title"><img src="http://pic002.cnblogs.com/images/2012/451207/2012100814082487.jpg" alt="关闭" />标题名称</div>
<div class="content">
//弹出窗口中显示的内容
<button onclick='windowClose()'><h1>取消窗口</h1></button>
</div>
</div>
$(function(){
//按钮点击事件
$("#btn_center").click(function () {
popCenterWindow();
});
});
Songsong
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 最后一次说说闭包
- Ajax
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法
- Redux系列02:一个炒鸡简单的react+redux例子
- JavaScript 各种遍历方式详解
- call/apply/bind 的理解与实例分享