jq打开浏览器新窗口_jquery打开新的窗口

使用本代码可以实现打开一个新的窗口,窗口的位置可变

html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

jQuery弹出窗口

.window{

width:250px;

background-color:#d0def0;

position:absolute;

padding:2px;

margin:5px;

display:none;

}

.content{

height:150px;

background-color:#FFF;

font-size:14px;

overflow:auto;

}

.title{

padding:2px;

color:#0CF;

font-size:14px;

}

.title img{

float:right;

}

$(document).ready(function () {

$("#btn_center").click(function () {

popCenterWindow();

});

$("#btn_right").click(function () {

popRightWindow();

});

$("#btn_left").click(function () {

popLeftWindow();

});

});

居中窗口
居中窗口
居左窗口
居左窗口
居右窗口
居右窗口

//获取窗口的高度

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();

上述代码所使用的图片我上传至百度盘,地址为: http://pan.baidu.com/s/1hqhDs9I ,上述代码使用的jquery.min文件自己可以去百度搜索一下,下载一个即可使用。

页面效果如下:

39c48ae1be87f0d499707ccd45318b89.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值