以下是 jQuery类似窗帘左右拉开动画特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.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" />
<meta name="viewport" content="width=device-width" />
<title>jQuery类似窗帘左右拉开动画特效</title>
<script type="text/javascript" src="js/jquery-1.js"></script>
<style type="text/css">
body {
/*background-color: #0066ff;*/
background-image: url(images/bg.jpg);
color: #333;
font-size: 12px;
margin: 0;
padding: 0;
overflow:hidden;
}
.main {
width: 1280px;
height: 600px;
padding: 0;
margin: 0 auto;
border-radius: 10px;
background-image: url(images/bg-index.png);
margin-top: 10px;
}
#leftPie, #rightPie {
position: absolute;
top: 0px;
background-color: #0E85FD;
width: 50%;
height: 100%;
opacity: 0.8;
filter: alpha(opacity=80);
}
#leftPie {
left: 0;
}
#rightPie {
left: 50%;
}
</style>
</head>
<body>
<div id="leftPie"></div>
<div id="rightPie"></div>
<div class="main"></div>
<script type="text/javascript">
/*
裁剪效果
o:jq
d:方向,1=向左,2=向右
n:递减的单位(相素)
*/
function clip(o, d, n) {
var w = o.width();
var h = o.height();
var offset = o.offset();
var l = offset.left;
var t = offset.top;
var pw = o.parent().width();
if (d == 1) {
w -= n;
o.width(w);
return w > 0;
}
else if (d == 2) {
l += n;
o.css("left", l);
return pw > l;
}
return true;
}
function clipL() {
var r = clip($("#leftPie"), 1, 20);
if (!r) {
clearInterval(timL);
$("#leftPie").remove();
}
}
var timL = setInterval("clipL()", 100);
function clipR() {
var r = clip($("#rightPie"), 2, 20);
if (!r) {
clearInterval(timR);
$("#rightPie").remove();
}
}
var timR = setInterval("clipR()", 100);
</script>
</body>
</html>