Jquery实现弹出窗口效果
2014-03-10 16:13
633 查看
在程序的编写过程中,许多小功能小技巧是很实用的,这里和大家分享一个,积累多了,就不容易卡住了。 jquery实现弹出窗口效果,用jquery实现图片任意点击,到任意地方去,很好用也很好看的效果
<!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>弹出窗口效果</title>
<style type="text/css">
.window{
.content{
.title img{
</style> <script type="text/javascript" language="javascript" src="../../jquery-1.7.1.min.js"> </script> <script type="text/javascript" language="javascript" src="window.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function(){
</script> </head> <body> <input type="button" value="居中窗口" id="btn_center"> <input type="button" value="居左下角" id="btn_left"> <input type="button" value="居右下角" id="btn_right">
<img src="../../images/close.jpg" />csdn欢迎您-居中窗口
爱的供养 呼吸的痛
<img src="../../images/close.jpg" />csdn欢迎您-居左窗口
爱的供养 呼吸的痛
<img src="../../images/close.jpg" />csdn欢迎您-居右窗口
爱的供养 呼吸的痛
</body> </html> [html] //获取窗口的高度 var windowHeight; //获取窗口的宽度 var windowWidth; //获取弹窗的宽度 var popWidth; //获取弹窗高度 var popHeight; function init(){
} //关闭窗口的方法 function 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>弹出窗口效果</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> <script type="text/javascript" language="javascript" src="../../jquery-1.7.1.min.js"> </script> <script type="text/javascript" language="javascript" src="window.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function(){
$("#btn_center").click(function(){ popCenterWindow(); }); $("#btn_right").click(function(){ popRightWindow(); }); $("#btn_left").click(function(){ popLeftWindow(); }); });
</script> </head> <body> <input type="button" value="居中窗口" id="btn_center"> <input type="button" value="居左下角" id="btn_left"> <input type="button" value="居右下角" id="btn_right">
<img src="../../images/close.jpg" />csdn欢迎您-居中窗口
爱的供养 呼吸的痛
<img src="../../images/close.jpg" />csdn欢迎您-居左窗口
爱的供养 呼吸的痛
<img src="../../images/close.jpg" />csdn欢迎您-居右窗口
爱的供养 呼吸的痛
</body> </html> [html] //获取窗口的高度 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(popY); //设定窗口的位置 $("#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).css("left",0).slideToggle("slow"); closeWindow(); } function popRightWindow(){ init(); //计算弹出窗口的左上角Y的偏移量 var popY=windowHeight-popHeight; var popX=windowWidth-popWidth; //alert(popY); //设定窗口的位置 $("#right").css("top",popY).css("left",popX).slideToggle("slow"); closeWindow(); }
相关文章推荐
- jQuery实现弹出带遮罩层的居中浮动窗口效果
- [原创+源码]jQuery实现弹出居、右下角、左下角窗口效果(一)
- 使用jquery实现弹出窗口效果(居中、左下角、右下角)
- [原创+源码]jQuery实现弹出居、右下角、左下角窗口效果(二)
- jquery实现弹出窗口效果的实例代码
- jQuery实现鼠标选中文字后弹出提示窗口效果【附demo源码】
- jquery实现弹出窗口效果的实例代码
- jquery实现弹出窗口效果的实例代码
- jQuery实现单击弹出Div层窗口效果(可关闭可拖动)
- jquery实现弹出窗口效果
- jQuery实现弹出居、右下角、左下角窗口效果(一)
- jQuery实现单击弹出Div层窗口效果(可关闭可拖动)
- jQuery实现弹出居、右下角、左下角窗口效果(二)
- 仿XP关机效果的弹出窗口(JS+样式实现)
- jQuery实现点击文本框弹出热门标签的提示效果
- jQuery DIV弹出效果实现代码
- 在原有网页上弹出一个子窗口并且实现半透明背景,原网页的滚动效果失效
- 用户控件 + ScriptManager 实现点击后弹出窗口且窗口坐标追随点击位置效果
- JQuery+JQuery ui实现的弹出窗口
- javascript实现右侧弹出“分享到”窗口效果