概述
jquery_windows.html文件
<!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>
<link type="text/css" rel="stylesheet" href="css.css">
<script src="../../jquery/jquery-1.7.1.js"></script>
<script src="window.js"></script>
<script>
$(document).ready(function (){
//利用toggle方法实现显示和隐藏
$('#btn_center').click(function (){
$(window).scroll(function (){
popCenterWindow();
});
});
$('#btn_left').click(function (){
$(window).scroll(function (){
popLeftButtomWindow();
});
});
$('#btn_right').click(function (){
$(window).scroll(function (){
popRightButtomWindow();
});
});
});
</script>
</head>
<body>
<input type="button" value="弹出中间窗口" id="btn_center"/>
<input type="button" value="弹出居左下角窗口" id="btn_left"/>
<input type="button" value="弹出居右下角窗口" id="btn_right"/>
<br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br>
<div id="center" class="window">
<div class="title">csdn欢迎你<img width="15px" height="15px" src="../../images/clone.png"></div>
<div class="content">费水电费水电费你</div>
</div>
<div
id="left" class="window">
<div class="title">csdn欢迎你<img width="15px" height="15px" src="../../images/clone.png"></div>
<div class="content">费水电费水电费你</div>
</div>
<div
id="right" class="window">
<div class="title">csdn欢迎你<img width="15px" height="15px" src="../../images/clone.png"></div>
<div class="content">费水电费水电费你</div>
</div>
</body>
</html>
window.js文件
// JavaScript Document
//定义一些变量
//获取窗口的高度
var windowHeight;
//获得窗口的宽度
var windowWidth;
//获得弹窗的高度
var popHeight;
//获得弹窗的宽度
var popWidth;
//获取滚动条的高度
var scrollTop;
var scrollLeft;
//延迟时间
var timeout;
function init(){
windowHeight=$(window).height();
windowWidth=$(window).width();
popHeight=$(".window").height();
popWidth=$(".window").width();
scrollTop=$(window).scrollTop();
scrollLeft=$(window).scrollLeft();
}
//关闭窗口的方法
function closeWindow(){
//根据div找到x号的图片,加单击事件,并且关闭窗口
$('.title img').click(function (){
$(this).parent().parent().hide('slow');
});
}
//定义弹出居中窗口的方法
function popCenterWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
//计算弹出窗口的左上角y的偏移量
var popY=(windowHeight-popHeight)/2+scrollTop;
var popX=(windowWidth-popWidth)/2+scrollLeft;
//设定窗口的位置
$('#center').animate({top:popY,left:popX},300).show('slow');
},300);
//调用关闭窗口
closeWindow();
}
//定义弹出左下角的效果
function popLeftButtomWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
//首先要初始化参数
init();
var popY=(windowHeight+scrollTop-popHeight);
var popX=scrollLeft;
//设定窗口的位置
$('#left').animate({top:popY,left:popX},300).show('slow');
},300);
//调用关闭窗口
closeWindow();
}
//定义弹出右下角窗口的效果
function popRightButtomWindow(){
//先清空上一次延迟
clearTimeout(timeout);
timeout=setTimeout(function (){
//首先要初始化参数
init();
var popY=windowHeight+scrollTop-popHeight-10;
var popX=windowWidth+scrollLeft-popWidth-10;
//设定窗口的位置
//$('#center').css('top',popY).css('left',popX).show('slow');
$('#right').animate({top:popY,left:popX},300).show('slow');
},300);
//调用关闭窗口
closeWindow();
}
css.css文件
@charset "utf-8";
/* CSS Document */
.window{
width:250px;
background-color:#6FF;
padding:2px;
margin:5px;
position:absolute;
display:none;}
.content{
height:150px;
background-color:#FFF;
padding:2px;
overflow:auto;
}
.title{
padding:2px;
color:#699;
font-size:14px;
}
.title img{
cursor:pointer;
float:right;
}
最后
以上就是笨笨电脑为你收集整理的jquery实现居中、左下角、右下角窗口效果的全部内容,希望文章能够帮你解决jquery实现居中、左下角、右下角窗口效果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复