jQuery快顯視窗完整代碼(置中,居左,居右)

來源:互聯網
上載者:User

核心代碼:
複製代碼 代碼如下:
//擷取視窗的高度
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('www.jb51.net');
//設定視窗的位置
$("#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();
}

完整代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jQuery快顯視窗 - 指令碼之家</title> <style type="text/css"> .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; } </style> </head> <body> <input type="button" value="置中視窗" id="btn_center" /> <input type="button" value="居左下角" id="btn_left" /> <input type="button" value="居右下角" id="btn_right" /> 指令碼之家-置中視窗 www.jb51.net 指令碼之家-居左視窗 www.jb51.net 指令碼之家-居右視窗 www.jb51.net </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
作者 cnblogs jihua

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.