1.QQ空间相册展示
核心代码:
<script type="text/javascript">
var _index=0;
var bImg=null;
$("ul li").click(function(){
_index=$(this).index(); //获取序列号
$(".gray").show(); //显示
$(".showImg").show(); //显示
bImg=$(this).find("img").attr("bigsrc"); //获取大图的src
$(".showImg img.show_bimg").attr("src",bImg); //attr设置属性值
});
$(".gray").click(function(){
$(".gray").hide(); //隐藏
$(".showImg").hide();
});
$(".showImg img.but_r").click(function(){
_index++;
if(_index>8)
{
_index=8;
alert("右边到头了");
}
bImg=$("ul li").eq(_index).find("img").attr("bigsrc");
$(".showImg img.show_bimg").attr("src",bImg);
});
//点击左边切换按扭
$(".showImg img.but_l").click(function(){
_index--;
if(_index<0)
{
_index=0;
alert("左边到头了");
}
bImg=$("ul li").eq(_index).find("img").attr("bigsrc");
$(".showImg img.show_bimg").attr("src",bImg);
});
</script>
关键点:
a .获取到小图的索引
b .attr不仅能获取属性值还能设置属性值
$("img").attr("width"); //获取宽度
$("img").attr("width","300"); //设置宽度
attr详见:http://www.w3school.com.cn/jquery/attributes_attr.asp
源代码:
总结:
1、如何在页面当中,构建一个有宽度,高度的长方形容器(div盒子模型)
2、讲到了外边距的概念( margin ),解决了外边距的兼容型问题 *{margin:0px;}
3、利用外边距的概念,控制长方形在水平方向距中,
并且与上面有一定间距 margin:上(30px) 左右(auto) 下(0px);
讲到了内边距的概念 padding,解决了内边距的兼容问题 *{padding:0px;}
5、讲到了浮动的概念(要使竖直方向的长方形(li)变成水平,给 li加上左浮动)float:left;
6、如何给页面当中的元素添加边框线 border:粗细(4px) 风格(solid) 颜色(#fff);
7、利用最新技术 html5+css3制作阴影效果 box-shadow:水平偏移 竖直偏移 模糊半径 颜色;
8、如何在页面当中,插入一张图片 img src =”地址” />
9、利用固定定位。来制作半透明的图层;
如何设置背景颜色的透明(background:rgba(0,0,0,0.6);)
10、利用绝对定位来制作我们大图展示区块 (position:absolute; left , top)
<!doctype html>
<html lang="en">
<head>
<!--网站编码格式,UTF-8 国际编码,GBK或 gb2312 中文编码-->
<meta charset="UTF-8">
<meta name="Keywords" content="关键词一,关键词二">
<meta name="Description" content="网站描述内容">
<title>Document</title>
<style type="text/css">
*{
padding:0px;
margin:0px;
}
#main{
width:1000px;
height:640px;
margin:30px auto 0px;
}
#main ul li{
width:288px;
height:180px;
border:4px solid #fff;
list-style-type:none;
float:left;
margin:10px 17px;
box-shadow:5px 5px 10px #000;
}
.gray{
width:100%;
height:100%;
background:rgba(0,0,0,.6);
position:fixed;
left:0px;
top:0px;
}
.showImg{
width:650px;
height:406px;
background:red;
position:absolute;
top:50%;
margin-top:-203px;
left:50%;
margin-left:-325px;
border:solid 10px #fff;
}
.showImg img.but_l{
position:absolute;
top:170px;
left:-70px;
}
.showImg img.but_r{
position:absolute;
top:170px;
right:-70px;
}
</style>
</head>
<body>
<!--图片列表开始-->
<div id="main">
<ul>
<li>
<img src="images/s1.jpg" bigsrc="images/big1.jpg">
</li>
<li>
<img src="images/s2.jpg" bigsrc="images/big2.jpg">
</li>
<li>
<img src="images/s3.jpg" bigsrc="images/big3.jpg">
</li>
<li>
<img src="images/s4.jpg" bigsrc="images/big4.jpg">
</li>
<li>
<img src="images/s5.jpg" bigsrc="images/big5.jpg">
</li>
<li>
<img src="images/s6.jpg" bigsrc="images/big6.jpg">
</li>
<li>
<img src="images/s7.jpg" bigsrc="images/big7.jpg">
</li>
<li>
<img src="images/s8.jpg" bigsrc="images/big8.jpg">
</li>
<li>
<img src="images/s9.jpg" bigsrc="images/big9.jpg">
</li>
</ul>
</div>
<!--图片列表结束-->
<!--半透明的图层开始-->
<div class="gray" style="display:none;">
</div>
<!--半透明的图层结束-->
<!--展示大图区开始-->
<div class="showImg" style="display:none">
<img src="images/big4.jpg" class="show_bimg">
<img src="images/dirl.png" class="but_l">
<img src="images/dirr.png" class="but_r">
</div>
<!--展示大图区结束-->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
var _index=0;
var bImg=null;
$("ul li").click(function(){
_index=$(this).index();
$(".gray").show();
$(".showImg").show();
bImg=$(this).find("img").attr("bigsrc");
$(".showImg img.show_bimg").attr("src",bImg);
});
$(".gray").click(function(){
$(".gray").hide();
$(".showImg").hide();
});
$(".showImg img.but_r").click(function(){
_index++;
if(_index>8)
{
_index=8;
alert("右边到头了");
}
bImg=$("ul li").eq(_index).find("img").attr("bigsrc");
$(".showImg img.show_bimg").attr("src",bImg);
});
$(".showImg img.but_l").click(function(){
_index--;
if(_index<0)
{
_index=0;
alert("左边到头了");
}
bImg=$("ul li").eq(_index).find("img").attr("bigsrc");
$(".showImg img.show_bimg").attr("src",bImg);
});
</script>
</body>
</html>
- 列表内容
核心代码:
$(function(){
$("div").click(function(){
$(this).stop(true,true);
$("div[title=selected]").stop(true,true);
var left1=$(this).css("left");
var top1=$(this).css("top");
var index1=$(this).css("z-index");
var left2=$("div[title=selected]").css("left");
var top2=$("div[title=selected]").css("top");
var index2=$("div[title=selected]").css("z-index");
$("div[title=selected]").animate({"left":left1,
"top":top1},1000).css("z-index",index1).removeAttr("title");
$(this).animate({"left":left2,"top":top2},1000)
.css("z-index",index2).attr("title","selected");
});
});
重点:
一,盒子阴影:
box-shadow:10px 10px 10px red;
水平位移,垂直位移,模糊半径,颜色
box-shadow:10px 10px 10px 10px red;
水平位移,垂直位移,阴影长度,模糊长度,颜色
二,jquery的stop()方法。
stop里面没有true时,停止执行当前动画,立马执行下一动画。
stop里面有一个true时,立马停止当前动画。
stop里面有两个true时,立马完成当前动画。
源代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
*{
paddding:0px;
margin:0px;
}
body{
background-color:#f3c1c1;
}
div{
position:absolute;
padding:5px;
background:#ffffff;
box-shadow:10px 10px 10px #cccccc;
border-radius:5px;
}
.p1{
top:50px;
left:50px;
z-index:1;
}
.p2{
top:50px;
left:690px;
z-index:1;
}
.p3{
top:100px;
left:210px;
z-index:2;
}
.p4{
top:100px;
left:530px;
z-index:2;
}
.p5{
top:152px;
left:370px;
z-index:3;
}
</style>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(function(){
$("div").click(function(){
$(this).stop(true,true);
$("div[title=selected]").stop(true,true);
var left1=$(this).css("left");
var top1=$(this).css("top");
var index1=$(this).css("z-index");
var left2=$("div[title=selected]").css("left");
var top2=$("div[title=selected]").css("top");
var index2=$("div[title=selected]").css("z-index");
$("div[title=selected]").animate({"left":left1,"top":top1},1000).css("z-index",index1).removeAttr("title");
$(this).animate({"left":left2,"top":top2},1000).css("z-index",index2).attr("title","selected");
});});
</script>
</head>
<body>
<div class="p1">
<img src="./img/1.jpg"/>
</div>
<div class="p2">
<img src="./img/2.jpg"/>
</div>
<div class="p3">
<img src="./img/3.jpg"/>
</div>
<div class="p4">
<img src="./img/4.jpg"/>
</div>
<div class="p5" title="selected">
<img src="./img/5.jpg"/>
</div>
</body>
</html>