html代码:
<!-- 弹出层部分 -->
<div id="box">
<span id="closeBtn" style="color:white">关闭</span>
<a id="gameMerry" href="http://gamemake.org/html5_game/shengdan/">挑战一下</a>
</div>
/*弹出层部分*/
#box {display: none;position: absolute;width: 440px;height: 284px;background: url(../images/layer.jpg) no-repeat;z-index: 200;
}
#closeBtn {position: absolute;right: 10px;top: 10px;cursor: pointer;color: #000 ;
}
#greybackground {background: #000;display: block;z-index: 100;width: 100%;position: absolute;top: 0;left: 0;
}
#box p {position: absolute;left: 180px;bottom: 40px;}
#box p a {color: #fff;font-size: 16px;text-decoration: underline;}
#box p a:hover {text-decoration: none;}
$(function(){
var screenwidth,screenheight,mytop,getPosLeft,getPosTop;
screenwidth = $(window).width();
screenheight = $(window).height();
mytop = $(document).scrollTop();
getPosLeft = screenwidth/2 - 220;
getPosTop = screenheight/2 - 142;
$("#box").css({"left":getPosLeft,"top":getPosTop});
$(window).resize(function(){
screenwidth = $(window).width();
screenheight = $(window).height();
mytop = $(document).scrollTop();
getPosLeft = screenwidth/2 - 220;
getPosTop = screenheight/2 - 142;
$("#box").css({"left":getPosLeft,"top":getPosTop+mytop});
});
$(window).scroll(function(){
screenwidth = $(window).width();
screenheight = $(window).height();
mytop = $(document).scrollTop();
getPosLeft = screenwidth/2 - 220;
getPosTop = screenheight/2 - 142;
$("#box").css({"left":getPosLeft,"top":getPosTop+mytop});
});
$("#box").fadeIn("fast");
$("body").append("
<div id="greybackground"></div>
");
var documentheight = $(document).height();
$("#greybackground").css({"opacity":"0.5","height":documentheight});
$("#closeBtn").click(function() {
$("#box").hide();
$("#greybackground").remove();
return false;
});
});