以下是 JS图片卷帘门效果特效代码 的示例演示效果:
部分效果截图:
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=gb2312" />
<meta name="keywords" content="JS代码,图片特效,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为JS图片卷帘门效果,属于站长常用代码" />
<title>JS图片卷帘门效果</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.backgroundPosition.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//Set css in Firefox (Required to use the backgroundPosition js)
$('#shutter1').css({backgroundPosition: '0px 0px'});
$('#shutter2').css({backgroundPosition: '0px 0px'});
$('#shutter3').css({backgroundPosition: '0px 0px'});
$('#shutter4').css({backgroundPosition: '0px 0px'});
//Animate the shutter
$(".link").hover(function(){
$(this).parent().animate({backgroundPosition: '(0px -100px)'}, 500 );
}, function() {
$(this).parent().animate({backgroundPosition: '(0px 0px)'}, 500 );
});
});
</script>
</head>
<body>
<div align="center" ><br /><br />
<ul id="menuback">
<li class="shutter" id="shutter1"><a class="link" href="#" >Link 1</a></li>
<li class="shutter" id="shutter2"><a class="link" href="#" >Link 2</a></li>
<li class="shutter" id="shutter3"><a class="link" href="#" >Link 3</a></li>
<li class="shutter" id="shutter4"><a class="link" href="#" >Link 4</a></li>
</ul>
</div>
</body>
</html>
JS代码(jquery.backgroundPosition.js):
/** * @author Alexander Farkas * v. 1.02 */
(function($){
$.extend($.fx.step,{
backgroundPosition:function(fx){
if (fx.state === 0 && typeof fx.end == 'string'){
var start = $.curCSS(fx.elem,'backgroundPosition');
start = toArray(start);
fx.start = [start[0],start[2]];
var end = toArray(fx.end);
fx.end = [end[0],end[2]];
fx.unit = [end[1],end[3]];
}
var nowPosX = [];
nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
function toArray(strg){
strg = strg.replace(/left|top/g,'0px');
strg = strg.replace(/right|bottom/g,'100%');
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}
}
}
);
}
)(jQuery);
CSS代码(style.css):
*{margin:0px;padding:0px;}
body{}
a{outline-style:none;}
ul#menuback{margin:50px auto;list-style:none;background:url(../images/menu-bg.jpg);width:800px;overflow:auto;}
ul#menuback li.shutter{width:200px;height:100px;display:block;float:left;}
ul#menuback li#shutter1{background:url(../images/shutter-africanplains.jpg) no-repeat;}
ul#menuback li#shutter2{background:url(../images/shutter-reptiles.jpg) no-repeat;}
ul#menuback li#shutter3{background:url(../images/shutter-aviary.jpg) no-repeat;}
ul#menuback li#shutter4{background:url(../images/shutter-arcticzone.jpg) no-repeat;}
a.link{width:200px;height:100px;display:block;background:url(../images/window.png) no-repeat bottom center;text-indent:-9999px;}