效果如下:

其实实现起来很简单,就是控制 宽 高的变化,然后给他加上transition 过度而已。觉得代码没什么难的地方,就不打注释了,如果哪里有不懂的话,可以直接评论呢。

直接上源码

html代码:

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./css/index.css">
</head> <body>
<div class="wra">
<ul class="content">
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
<li class="items">
<div class="inner">
<h2>bird</h2>
<div class="bg">
<div class="close"></div>
</div>
</div>
</li>
</ul>
</div>
<script src="./js/jquery.js"></script>
<script src="./js/index.js"></script>
</body> </html>

css代码:

*{
padding: 0;
margin: 0;
list-style: none;
box-sizing: border-box;
} :root,body,.wra{
width: 100%;
height: 100%;
}
.wra{
background-color: black;
display: flex;
justify-content: center;
align-items: center;
} .wra .content{
width: 80%;
height: 80%;
display: flex;
justify-content: space-between;
align-items: center;
overflow: hidden;
} .wra .content .items{
position: relative;
height: 100%;
width: 16%;
border-radius: 30px;
transition: height .5s linear, width .7s .5s linear;
}
.wra .content .items:hover .inner .bg{
opacity: 1;
}
.wra .content .items:hover h2{
font-size: 30px;
}
.wra .content .items h2{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 20px;
z-index: 1;
transition: font-size .3s , opacity .3s;
}
.wra.wra-active .content .items h2{
opacity: 0;
}
.wra .content .items .inner{
width: 100%;
height: 100%;
transition: transform .5s ;
}
.wra .content .items .inner .bg{
width: 100%;
height: 100%;
background-size: cover;
background-position: center center;
border-radius: 30px;
opacity: .5;
transition: opacity .3s;
}
.wra .content .items:nth-of-type(1) .inner .bg{
background-image: url('../img/1.jpg');
}
.wra .content .items:nth-of-type(2) .inner .bg{
background-image: url('../img/2.jpg');
}
.wra .content .items:nth-of-type(3) .inner .bg{
background-image: url('../img/3.jpg');
}
.wra .content .items:nth-of-type(4) .inner .bg{
background-image: url('../img/4.jpg');
}
.wra .content .items:nth-of-type(5) .inner .bg{
background-image: url('../img/5.jpg');
}
.wra .content .items:nth-of-type(6) .inner .bg{
background-image: url('../img/6.jpg');
} .wra .content .items.active{
width: 100%;
}
.wra .content .items.active .inner .bg{
opacity: 1;
}
.wra.wra-active .content .items:not(.active){
width: 0%;
height: 0%;
} .wra .content .items .inner{
transform: translateY(101%);
} .wra.init .content .items .inner{
transform: translateY(0%);
} .wra.init .content .items:nth-of-type(2) .inner{
transition-delay: .2s;
}
.wra.init .content .items:nth-of-type(3) .inner{
transition-delay: .3s;
}
.wra.init .content .items:nth-of-type(4) .inner{
transition-delay: .4s;
}
.wra.init .content .items:nth-of-type(5) .inner{
transition-delay: .5s;
}
.wra.init .content .items:nth-of-type(6) .inner{
transition-delay: .6s;
}
.wra .content .items .inner .bg .close{
opacity: 0;
transform: rotateZ(0deg);
}
.wra .content .items.active .inner .bg .close{
position: absolute;
right: 30px;
top: 30px;
width: 30px;
height: 30px;
opacity: 1;
transform: rotateZ(360deg);
}
.wra .content .items.active .inner .bg .close{
transition: opacity .3s linear 1s, transform .5s linear 1s;
}
.wra .content .items.active .inner .bg .close::after,.wra .content .items.active .inner .bg .close::before{
position: absolute;
content: "";
width: 30px;
height: 4px;
background-color: #fff;
top: calc(50% - 2px);
}
.wra .content .items.active .inner .bg .close::after{
transform: rotateZ(45deg);
}
.wra .content .items.active .inner .bg .close::before{
transform: rotateZ(-45deg);
}

jquery代码:

setTimeout(function(){
$('.wra').addClass('init');
},400)
$('.items').on('click', function(){
$(this).addClass('active');
$('.wra').addClass('wra-active');
})
$('.close').on('click', function(e){
e.stopPropagation();
$('.items').removeClass('active');
$('.wra').removeClass('wra-active');
})

利用css3实现照片列表展开小demo的更多相关文章

  1. Android学习小Demo(19)利用Loader来实时接收短信

    之前写过一篇文章<Android学习小Demo(13)Android中关于ContentObserver的使用>,在里面利用ContentOberver去监測短信URI内容的变化.我们先来 ...

  2. [置顶] 利用CXF发布webService的小demo

    其实webService的发布不仅仅只有xfire,今天,给大家介绍一下用CXF发布一个webService的小demo,CXF也是我做webService用的第一个框架... 先将相关的jar引进来 ...

  3. css3的一个小demo(箭头hover变化)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. jQuery/CSS3实现图片层叠展开特效

    这是一款基于jQuery和CSS3的图片层叠展开特效,让鼠标滑过图片时即可触发这些特效.其中有一款就像扇子展开收拢一样,看起来效果都非常不错.当然本文主要还是来分析一下用jQuery实现这一效果的方法 ...

  5. 超可爱 纯CSS3实现的小猪、小老鼠、小牛

    原文:超可爱 纯CSS3实现的小猪.小老鼠.小牛 利用纯CSS3绘制一些人物.动物.风景已经不是一件新鲜的事情了,主要是利用CSS3可以让直线变成任意的曲线,于是简单的矢量图形绘制对CSS3来说就小菜 ...

  6. 使用纯 CSS 实现 Google Photos 照片列表布局

    文章太长,因为介绍了如何一步一步进化到最后接近完美的效果的,不想读的同学可以直接跳到最后一个大标题之后看代码.demo及原理就好,或者也可以直接看下面这个链接的源代码. 不过还是建议顺序读下去,因为后 ...

  7. Nancy之基于Nancy.Owin的小Demo

    前面做了基于Nancy.Hosting.Aspnet和Nancy.Hosting.Self的小Demo 今天我们来做个基于Nancy.Owin的小Demo 开始之前我们来说说什么是Owin和Katan ...

  8. 利用CSS3实现图片无间断轮播图的实现思路

    前言:图片轮播效果现在在各大网站都是非常普遍的,以前我们都是通过postion的left or right来控制dom的移动,这里我要说的是利用css3来制作轮播!相比以前通过postion来移动do ...

  9. 利用CSS3实现圆角的outline效果的教程

    一.首先,outline是个很牛的东西1. border近亲outline和border是近亲,为什么这么讲呢?首先,都是给元素外面套框框的:其次,支持的属性值几乎都是一样的,例如,outline-s ...

随机推荐

  1. 阿里云ecs,rds,redis优惠套餐

    阿里云ECS优惠套餐 阿里云RDS优惠套餐 阿里云REDIS优惠套餐 阿里云REDIS集群版 阿里云短信资源包

  2. docker-compose启动consul集群

    version: '2.0' services: consul-server1: image: consul:latest hostname: "consul-server1" p ...

  3. Parquet 源码解析

    date: 2020-07-20 16:15:00 updated: 2020-07-27 13:40:00 Parquet 源码解析 Parquet文件是以二进制方式存储的,所以是不可以直接读取的, ...

  4. vue-router入门随笔

    下面整理根据官方文档以及自我理解整理,如有不足,请指教. 下面是来自一段官方的原话. Vue Router 是 Vue.js 官方的路由管理器.它和 Vue.js 的核心深度集成,让构建单页面应用变得 ...

  5. Spring源码分析之`BeanFactoryPostProcessor`调用过程

    前文传送门: Spring源码分析之预启动流程 Spring源码分析之BeanFactory体系结构 本文内容: AbstractApplicationContext#refresh前部分的一点小内容 ...

  6. F. Make It Connected 解析(思維、MST)

    Codeforce 1095 F. Make It Connected 解析(思維.MST) 今天我們來看看CF1095F 題目連結 題目 給你\(n\)個點,每個點\(u\)還有一個值\(a[u]\ ...

  7. 如何将Docker升级到最新版本

    很早以前,已经使用过了Docker了,但是没有使用过 Docker 部署 NetCore 3.1 的应用程序,今天部署的时候发生了一些问题,解决办法:Docker 版本太低了,那就升级一下.下面是具体 ...

  8. 快来,我悄悄的给你说几个HashCode的破事。

    这是why技术的第 72 篇原创文章 Hash冲突是怎么回事 在这个文章正式开始之前,先几句话把这个问题说清楚了:我们常说的 Hash 冲突到底是怎么回事? 直接上个图片: 你说你看到这个图片的时候想 ...

  9. 深入web workers (上)

    前段时间,为了优化某个有点复杂的功能,我采用了shared workers + indexDB,构建了一个高性能的多页面共享的服务.由于是第一次真正意义上的运用workers,比以前单纯的学习有更多体 ...

  10. Git命令之diff

    工作区(working tree),暂存区(index /stage),本地仓库(repository) git跟不同的参数,比较不同的区间的版本. git diff:是查看working tree与 ...