0

0

css实现点击切换图片效果

王林

王林

发布时间:2020-09-11 16:36:39

|

4843人浏览过

|

来源于csdn

转载

css实现点击切换图片效果

我们先来看下效果图:

(相关教程:CSS教程

切换前:

ba59550ce0f8d5e8afb938c05fba548.png

立即学习前端免费学习笔记(深入)”;

切换中:
4b90e696a5e4bd9c4456cfeba7a517d.png

svg点击图片切换动画特效
svg点击图片切换动画特效

一款svg点击图片切换动画特效

下载

切换成功:

7af835e1e8ae016542c805eceaf8e41.png

HTML代码:





来自Limou的尝试解读




		

来自Limou的尝试解读

1 2 3 4
Images1 Images2 Images3 Images4
Images1 Images2 Images3 Images4
Images1 Images2 Images3 Images4
Images1 Images2 Images3 Images4

我的世界钻石

小动物松鼠

上古卷轴雪漫城随从

守望先锋不知道是谁

CSS代码:

@charset "utf-8";
/* CSS Document */

h1{
	text-align: center;
	color:deepskyblue;
	text-shadow: 1px 1px 1px rgba(0,0,0,0.1);/*设置字体的阴影*/
}
/*顶部a标签动画与样式  开始*/
.button{
	text-align: center;
	height: 80px;
	width: 100%;
	display: block;
}
.button a{
	height: 60px;
	width: 60px;
	display: inline-block;/*布局属性:内联-块,
	使其成为并排显示的块级元素,让其宽高可以编辑,且宽高和内外边距可以超过父级元素*/
	text-decoration: none;/*去除下划线*/
	line-height: 60px;
	border-radius: 50%;
	/*设置字符的行高,通常用于自定义的某些样式,字符在顶部或底部时使用,让其上下居中*/
	background-color: rgba(104,171,194,0.5);
	transition:background-color 0.15s linear;/*组合写法*/
	/*transition-property	规定设置过渡效果的 CSS 属性的名称。
				-duration	规定完成过渡效果需要多少秒或毫秒。
				-timing-function	规定速度效果的速度曲线。
				-delay	定义过渡效果开始时间。*/
	color: white;
}
.button a:hover{
	background-color: rgba(255,255,255);
	color:#68ABC2;
	transition:background-color 0.15s linear;
}
/*顶部a标签动画与样式  开始*/


/*图片的样式与动画  开始*/
.SpanStyle{
	width: 100%;
	height: 400px;
	z-index: 1;
	position: absolute;
	top: 0;
	background-repeat: no-repeat;
	background-size: 100% 100%;
	background-position: 0 0;
}
.SpanStyle div{
	width: 25%;
	height: 100%;
	float: left;
	position: relative;
	overflow: hidden;
	background-repeat: no-repeat;
}
.SpanStyle div span{
	position: absolute;
	width: 100%;
	height: 100%;
	top: 0px;
	left: -100%;/*设置元素初始位置,为动画准备*/
	z-index: 2;
	color: rgba(255,255,255,0);
	background-repeat: no-repeat;
	background-size: 400% 100%;
}

/*设置图片在元素的位置*/
.SpanStyle div:nth-child(1) span{
	background-position: 0% 0px;
}
.SpanStyle div:nth-child(2) span{
	background-position: 33.5% 0px;
}
.SpanStyle div:nth-child(3) span{
	background-position: 66.5% 0px;
}
.SpanStyle div:nth-child(4) span{
	background-position: 100% 0px;
}

/*父级元素下的 某个input标签和 它的类名:选中后匹配元素(单复选框专用) ~ 
一个父级元素下的div里面的Span元素:匹配元素(第N个) */
/*定义指定的input标签点击后将匹配的元素绑定新图片*/
.Images input.cr-in-img-1:checked ~ .SpanStyle, 
.SpanStyle div span:nth-child(1){
	background-image: url(../images/1.jpg);
}
.Images input.cr-in-img-2:checked ~ .SpanStyle,
.SpanStyle div span:nth-child(2){
	background-image: url(../images/2.jpg);
}
.Images input.cr-in-img-3:checked ~ .SpanStyle,
.SpanStyle div span:nth-child(3){
	background-image: url(../images/3.jpg);
}
.Images input.cr-in-img-4:checked ~ .SpanStyle,
.SpanStyle div span:nth-child(4){
	background-image: url(../images/4.jpg);
}

/*定义指定的input标签点击后将绑定的新图片所在的元素插入*/
.Images input.cr-in-img-1:checked ~ .SpanStyle div span:nth-child(1),
.Images input.cr-in-img-2:checked ~ .SpanStyle div span:nth-child(2),
.Images input.cr-in-img-3:checked ~ .SpanStyle div span:nth-child(3),
.Images input.cr-in-img-4:checked ~ .SpanStyle div span:nth-child(4)
{
	animation: none;
	transition: left 0.8s ease-in-out;
	left: 0%;
	z-index: 10;
}

/*定义指定的input标签点击后将要替换的旧图片所在的元素撤出*/
.Images input:checked ~ .SpanStyle div span{
	animation: slideOut 0.8s ease-in-out;
}

@keyframes slideOut{
	0%{ left: 0%; }
	100%{ left: 100%; }
}
/*图片的样式与动画  结束*/


/*文本动画与样式  开始*/
.Images{
	height: 400px;
	width: 40%;
	text-align: center;
	position: relative;
	margin: 2% auto 0 auto;
	border: 20px solid #fff;
	box-shadow: 1px 1px 3px rgba(0,0,0,0.1);
}
.Images input{
	display: none;
}
.Images label{
	font-style: italic; /*字体样式:倾斜*/
	margin-top: 350px;
	text-align: center;
	width: 25%;
	height: 30px;
	cursor: pointer;/*光标:手*/
	color: #fff; /*字体颜色*/
	position: relative;
	float: left;
	line-height: 34px;
	font-size: 24px;/*字号,字体大小*/
	z-index: 5;
}
.Images label:before{
	content:'';/*绑定文本也可以绑定文件*/
	width: 34px;
	height: 34px;
	background: rgba(130,195,217,0.9);
	position: absolute;
	left: 50%;
	margin-left: -14px;
	border-radius: 50%;
	box-shadow: 0px 0px 0px 4px rgba(255,255,255,0.3);
	z-index:-1;
}
.Images label:after{
	width: 1px;
	height: 400px;
	content: '';
	background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%);
    position: absolute;
	bottom: -20px;
	right: 0px;
}

.h3Span h3{
	position: absolute;
	width: 100%;
	top: 45%;
	z-index: 10;
	text-align: center;
	opacity: 0;
	color: #fff;
	text-shadow: 1px 1px 1px rgba(0,0,0,0.1);
	transition: opacity 0.8s ease-in-out;
}
.h3Span h3 span{
	z-index: 10;
	position: absolute;
	width: 100%;
	left: 0px;
	text-align: center;
	opacity: 1;
}
.h3Span h3 span:nth-child(1){
	font-family: 'NSimSun';
	font-size: 50px;
    display: block;
    letter-spacing: 7px;
}
.h3Span h3 span:nth-child(2){
	margin-top: 84px;
	letter-spacing: 0px;
	background: rgba(104,171,194,0.9);
	font-size: 14px;
	padding: 10px 0px;
	font-style: italic;
	transition: opacity 0.8s ease-in-out;
}

.Images input.cr-in-img-1:checked ~ .h3Span h3:nth-child(1),
.Images input.cr-in-img-2:checked ~ .h3Span h3:nth-child(2),
.Images input.cr-in-img-3:checked ~ .h3Span h3:nth-child(3),
.Images input.cr-in-img-4:checked ~ .h3Span h3:nth-child(4){
	opacity: 1;
}
/*文本的动画与样式  结束*/


/*页面缩小显示复选框*/
@media screen and (max-width: 1200px) {
	.Images input{
		display: inline;
		width: 22%;
		margin-top: 350px;
		z-index: 10;
		position: relative;
	}
	.Images label{
		display: none;
	}
}

相关专题

更多
css
css

css是层叠样式表,用来表现HTML或XML等文件样式的计算机语言,不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。php中文网还为大家带来html的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

522

2023.06.15

css居中
css居中

css居中:1、通过“margin: 0 auto; text-align: center”实现水平居中;2、通过“display:flex”实现水平居中;3、通过“display:table-cell”和“margin-left”实现居中。本专题为大家提供css居中的相关的文章、下载、课程内容,供大家免费下载体验。

262

2023.07.27

css如何插入图片
css如何插入图片

cssCSS是层叠样式表(Cascading Style Sheets)的缩写。它是一种用于描述网页或应用程序外观和样式的标记语言。CSS可以控制网页的字体、颜色、布局、大小、背景、边框等方面,使得网页的外观更加美观和易于阅读。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

753

2023.07.28

css超出显示...
css超出显示...

在CSS中,当文本内容超出容器的宽度或高度时,可以使用省略号来表示被隐藏的文本内容。本专题为大家提供css超出显示...的相关文章,相关教程,供大家免费体验。

539

2023.08.01

css字体颜色
css字体颜色

CSS中,字体颜色可以通过属性color来设置,用于控制文本的前景色,字体颜色在网页设计中起到很重要的作用,具有以下表现作用:1、提升可读性;2、强调重点信息;3、营造氛围和美感;4、用于呈现品牌标识或与品牌形象相符的风格。

757

2023.08.10

什么是css
什么是css

CSS是层叠样式表(Cascading Style Sheets)的缩写,是一种用于描述网页(或其他基于 XML 的文档)样式与布局的标记语言,CSS的作用和意义如下:1、分离样式和内容;2、页面加载速度优化;3、实现响应式设计;4、确保整个网站的风格和样式保持统一。

604

2023.08.10

css三角形怎么写
css三角形怎么写

CSS可以通过多种方式实现三角形形状,本专题为大家提供css三角形怎么写的相关教程,大家可以免费体验。

560

2023.08.21

css设置文字颜色
css设置文字颜色

CSS(层叠样式表)可以用于设置文字颜色,这样做有以下好处和优势:1、增加网页的可视化效果;2、突出显示某些重要的信息或关键字;3、增强品牌识别度;4、提高网页的可访问性;5、引起不同的情感共鸣。

390

2023.08.22

Golang gRPC 服务开发与Protobuf实战
Golang gRPC 服务开发与Protobuf实战

本专题系统讲解 Golang 在 gRPC 服务开发中的完整实践,涵盖 Protobuf 定义与代码生成、gRPC 服务端与客户端实现、流式 RPC(Unary/Server/Client/Bidirectional)、错误处理、拦截器、中间件以及与 HTTP/REST 的对接方案。通过实际案例,帮助学习者掌握 使用 Go 构建高性能、强类型、可扩展的 RPC 服务体系,适用于微服务与内部系统通信场景。

8

2026.01.15

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Sass 教程
Sass 教程

共14课时 | 0.8万人学习

Bootstrap 5教程
Bootstrap 5教程

共46课时 | 2.9万人学习

CSS教程
CSS教程

共754课时 | 19万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号