js实现广告弹出框
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试</title>
<style type="text/css">
body {
background: #333333;
}
#winpop {
width: 400px;
height: 0px;
position: absolute;
right: 0;
bottom: 0;
border: 1px solid #999999;
margin: 0;
padding: 1px;
overflow: hidden;
display: none;
background: #FFFFFF
}
#winpop .title {
width: 100%;
height: 20px;
line-height: 20px;
background: #FFCC00;
font-weight: bold;
text-align: center;
font-size: 12px;
}
#winpop .con {
width: 100%;
height: 80px;
line-height: 80px;
font-weight: bold;
font-size: 12px;
color: red;
text-decoration: none;
text-align: center
}
#silu {
font-size: 13px;
color: #999999;
position: absolute;
right: 400px;
bottom: 400px;
text-align: right;
text-decoration: underline;
line-height: 22px;
}
.close {
position: absolute;
right: 4px;
top: -1px;
color: red;
cursor: pointer
}
</style>
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function() {
//默认加载广告
show_pop();
});
function show_pop() {
//获取广告图层的高度
var winpop = $('#winpop');
var popH = winpop.height();
if(popH >= 400) {
return;
}
//使广告图层可见
$('#winpop').css('display','block');
//设置定时器,每20毫秒升高广告图层4px
timer = setInterval("changeH(4)", 20);
}
function hid_pop() {
var winpop = $('#winpop');
var popH = winpop.height();
if(popH <= 0) {
return;
}
//设置定时器,每20毫秒降低广告图层4px
timer = setInterval("changeH(-4)", 20);
}
function changeH(addH) {
var winpop = $('#winpop');
var popH = winpop.height();
if (popH <= 400 && addH > 0 || popH >= 4 && addH < 0) {
winpop.height(popH + addH);
} else {
clearInterval(timer);
$(winpop).css('display',addH > 0 ? 'block' : 'none');
}
}
</script>
</head>
<body>
<div id="silu">
<button onclick="show_pop()">显示广告</button>
</div>
<div id="winpop">
<div class="title">
您有新的消息<span class="close" onclick="hid_pop()">X</span>
</div>
<div class="con">
<a href='http://lxzqz.iteye.com/' target="_blank">lxzqz的博客</a>
</div>
</div>
</body>
</html>