以下是 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=gb2312" />
<meta name="keywords" content="JS代码,相册代码,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为jQuery自适应图片大小相册代码,属于站长常用代码" />
<title>jq武魂官网容器适应图片大小而变化</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/lrtk.js"></script>
<style>
html{overflow:-moz-scrollbars-vertical ; overflow:scroll; overflow-x:hidden; overflow-y:hidden;} /*图片太高时出现了右侧滚动条 滚动条会让ul宽度变化的效果看起来有点震动! 所以这里去掉*/
*{padding:0 ; margin:0 ;}
ul{list-style:none;}
body{background:#CCCCCC;}
.container{width:100%; height:100%; margin-top:3%;}
.content{background:#ffffff; margin:0 auto; position:relative; width:220px; height:100px; border: 15px solid #ffffff;}
.content li{position:absolute; top:0; left:0; display:none;}
.content span{position:absolute; left:47%; top:45%;}
.content .left,.content .right{position:absolute; top:0; z-index:11;}
.content .left{cursor:url(images/cur-left.cur.ico), auto; left:0;}
.content .right{right:0; cursor:url(images/cur-right.cur.ico), auto;}
.bottom{height:0px; background:#ffffff; margin:0 auto; overflow:hidden; line-height:50px; padding: 0 15px;}
</style>
</head>
<body>
<div class="container">
<!-- 代码 开始 -->
<ul class="content">
<span><img src="images/5-121204193956-50.gif" width="32" height="32" /></span>
<div class="left"></div>
<div class="right"></div>
<li style="background:url(images/img_1.jpg); width:856px; height:482px;"></li>
<li style="background:url(images/img_2.jpg); width:904px; height:723px;"></li>
<li style="background:url(images/img_3.jpg); width:816px; height:459px;"></li>
<li style="background:url(images/img_4.jpg); width:860px; height:484px;"></li>
<li style="background:url(images/img_5.jpg); width:960px; height:540px;"></li>
<li style="background:url(images/img_6.jpg); width:910px; height:683px;"></li>
<li style="background:url(images/img_7.jpg); width:960px; height:540px;"></li>
</ul>
<div class="bottom">
共 <span id="imgdata">x</span> 张 / 第 <span id="xz">x</span> 张
</div>
<!-- 代码 结束 -->
</div>
</body>
</html>
JS代码(lrtk.js):
$(function (){
var x=0,width,height,ul=$(".content"),bottom=$(".bottom"),tfunction img_block(){
bottom.stop();
ul.stop();
$(".content li").css("display","none");
bottom.css({
"height":"0px"}
);
$("#xz").text(x+1);
width=parseInt($(".content li:eq("+x+")").css("width"));
height=parseInt($(".content li:eq("+x+")").css("height"));
ul.animate({
"width":width+"px","height":height+"px"}
,500,function (){
$(".content li:eq("+x+")").css("display","block");
bottom.css("width",width+"px");
bottom.animate({
"height":"50px"}
);
$(".left,.right").css({
"width":width/2+"px","height":height+"px"}
)}
);
}
;
function rights(){
if(x==$(".content li").length-1){
x=0;
}
else{
x++}
;
img_block();
}
;
$(document).ready(function(){
$("#imgdata").text($(".content li").length);
img_block();
t=setInterval(rights,4000);
}
);
$(".right").click(function (){
rights()}
);
$(".left").click(function (){
if(x==0){
x=$(".content li").length-1;
}
else{
x--}
;
img_block();
}
);
$(".right,.right").hover(function (){
clearTimeout(t)}
,function (){
t=setInterval(rights,4000)}
);
}
);