CSS3 渐变、变形、过渡、动画小结

2024-08-29 00:38

本文主要是介绍CSS3 渐变、变形、过渡、动画小结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CSS3 渐变(IE9&-用滤镜filter来兼容)

线性渐变:

linear-gradient([ [ <angle> | to <side-or-corner> ] ,]? <color-stop>[, <color-stop>]+)

<side-or-corner> = [left | right] || [top | bottom]   八个方向,to bottom是默认值,相当于180deg。

<color-stop> = <color> [ <length> | <percentage> ]?

例:background-image:linear-gradient(to left bottom, red 20%, orange 40%, yellow 85%,green 100%);

      background-image:linear-gradient(-135deg,#ccc, #fcf);

径向渐变:

radial-gradient([ [ <shape> || <size> ] [ at <position> ]? , | at <position>, ]?<color-stop>[ , <color-stop> ]+)

<position> = [ <length> | <percentage> | left | center| right ]? [ <length> | <percentage> | top | center②| bottom ]? 

确定圆心的位置,默认值为center。如果提供2个参数,第一个表示横坐标,第二个表示纵坐标;如果只提供一个,第二值默认为50%,即center.

<shape> = circle |ellipse   圆或椭圆

例:background-image:radial-gradient(circle at 50px top, red 30%, yellow,green, aliceblue);

重复线性渐变repeating-linear-gradient; 重复径向渐变repeating-radial-gradient;

例:background-image:repeating-radial-gradient(circle,red, yellow 10px, green 80px);

 

CSS3 变形transform

1D变形函数:translateX(), translateY(), scaleX(),scaleY(), skewX(), skewY()…

2D变形函数:translate(),scale(),skew(), rotateZ()…

3D变形函数:rotateX(), rotateY(), rotate3d(),translateZ(), translate3d(), scaleZ(), scale3d(), matrix3d(), perspective()…

 

transformnone<transform-function> [<transform-function>]*

transform-origin<percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]?   变形中心50% 50%

transform-styleflat | preserve-3d

                            flat: 所有子元素在2D平面呈现;preserve-3D:

perspectivenone<length>  景深,属性要设置在父元素上才有效;越小越靠近,越大趋近于none;

                       vs perspective函数用在变形元素上,可与其他transform函数一起使用;

perspective-origin<percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]?    透视中心50% 50%

backface-visibilityvisible | hidden

例:transform: translateX(18px) scaleY(0.8)rotate(18deg) skew(-18deg) //X平移+Y缩放+旋转+倾斜


CSS3 过渡 transition:

·实现属性开始值与结束值之间的平滑过渡;

transition:<single-transition>[,<single-transition>]*

<single-transition> = [ none | <transition-property> ] || <transition-duration> || <transition-timing-function> || <transition-delay>

<' transition-property '>:过渡属性

<' transition-duration '>:过渡持续时间

<' transition-timing-function '>:过渡动画函数

<' transition-delay '>:过渡延迟时间

<transition-timing-function> = ease | linear | ease-in | ease-out |ease-in-out | step-start | step-end | steps(<integer>[, [ start | end ] ]?) | cubic-bezier(<number><number><number><number>)

 

linear:线性过渡。等同于贝塞尔曲线(0.0, 0.0, 1.0,1.0)

ease:平滑过渡。等同于贝塞尔曲线(0.25, 0.1,0.25, 1.0)

ease-in:由慢到快。等同于贝塞尔曲线(0.42, 0, 1.0,1.0)

ease-out:由快到慢。等同于贝塞尔曲线(0, 0, 0.58,1.0)

ease-in-out:由慢到快再到慢。等同于贝塞尔曲线(0.42, 0, 0.58,1.0)

step-start:等同于 steps(1,start)

step-end:等同于 steps(1, end)

steps(<integer>[, [ start | end ] ]?):接受两个参数的步进函数。第一个参数必须为正整数,指定函数的步数。第二个参数取值可以是start或end,指定每一步的值发生变化的时间点。第二个参数是可选的,默认值为end。

cubic-bezier(<number>, <number>, <number>,<number>):特定的贝塞尔曲线类型,4个数值需在[0, 1]区间内

例:

.front{

  background-color:#fcf;

  border:3px solid grey;

  transition:background-color 1.5s ease-in, border-radius 1.5s ease-out, border-color 1.3s linear 0.2s

}

front:hover{

  background-color:#cec;

  border-radius:150px;

  border-color:transparent;

}

  

触发过渡的方式:CSS伪类如:hover、:focus…;媒体查询;JS切换类名…;

解决-webkit-留下痕迹的问题:硬件加速(添加-webkit-transform:translate(0));


CSS3 动画animation

·  transition只能指定属性的起止状态;animation通过指定“关键帧”来声明动画;

animation:<single-animation>[,<single-animation>]*

<single-animation> = <single-animation-name> || <time> || <single-animation-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state>

<' animation-name '>:动画名称,动画名必须对应一个@keyframes规则;

<' animation-duration '>:动画的持续时间;

<' animation-timing-function '>:动画过渡类型,与transition-timing-function类似;

<' animation-delay '>:动画延迟的时间

<' animation-iteration-count '>=infinite | <number>:对象动画的循环次数。默认值为1;

<' animation-direction '>=normal | reverse | alternate| alternate-reverse

alternate:先正常再反方向,交替运行;alternate-reverse:先反向再正向;

<' animation-fill-mode '>= none | forwards | backwards | both对象动画时间之外的状态;

<' animation-play-state '>= running | paused对象动画的状态。


animation实现的近似翻牌效果

<style>

.wrap{

  perspective:1000px;

}

.card{

  width:250px;

  height:350px;

  background-image:url(frontface.jpg);

  background-size:100% 100%;

}

.card:hover{

  animation: spin 5s linear infinite;

}

@keyframes spin{

  0%{ transform:rotateY(0); }

  25%{ background-image: url(frontface.jpg); }

  26%{ background-image: url(backface.jpg); }

  75%{ background-image: url(backface.jpg); }

  76%{ background-image: url(frontface.jpg); }

  100%{ transform:rotateY(360deg); }

}

</style>

<div class="wrap">

    <div class="card"></div>

</div>


/* 部分属性总结自 @飘零雾雨 《CSS参考手册》,灰色底色代表属性的默认值*/

这篇关于CSS3 渐变、变形、过渡、动画小结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1116343

相关文章

Java判断多个时间段是否重合的方法小结

《Java判断多个时间段是否重合的方法小结》这篇文章主要为大家详细介绍了Java中判断多个时间段是否重合的方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录判断多个时间段是否有间隔判断时间段集合是否与某时间段重合判断多个时间段是否有间隔实体类内容public class D

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

SpringBoot中使用 ThreadLocal 进行多线程上下文管理及注意事项小结

《SpringBoot中使用ThreadLocal进行多线程上下文管理及注意事项小结》本文详细介绍了ThreadLocal的原理、使用场景和示例代码,并在SpringBoot中使用ThreadLo... 目录前言技术积累1.什么是 ThreadLocal2. ThreadLocal 的原理2.1 线程隔离2

Spring AI Alibaba接入大模型时的依赖问题小结

《SpringAIAlibaba接入大模型时的依赖问题小结》文章介绍了如何在pom.xml文件中配置SpringAIAlibaba依赖,并提供了一个示例pom.xml文件,同时,建议将Maven仓... 目录(一)pom.XML文件:(二)application.yml配置文件(一)pom.xml文件:首

JS 实现复制到剪贴板的几种方式小结

《JS实现复制到剪贴板的几种方式小结》本文主要介绍了JS实现复制到剪贴板的几种方式小结,包括ClipboardAPI和document.execCommand这两种方法,具有一定的参考价值,感兴趣的... 目录一、Clipboard API相关属性方法二、document.execCommand优点:缺点:

Python创建Excel的4种方式小结

《Python创建Excel的4种方式小结》这篇文章主要为大家详细介绍了Python中创建Excel的4种常见方式,文中的示例代码简洁易懂,具有一定的参考价值,感兴趣的小伙伴可以学习一下... 目录库的安装代码1——pandas代码2——openpyxl代码3——xlsxwriterwww.cppcns.c

MyBatis-Flex BaseMapper的接口基本用法小结

《MyBatis-FlexBaseMapper的接口基本用法小结》本文主要介绍了MyBatis-FlexBaseMapper的接口基本用法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具... 目录MyBATis-Flex简单介绍特性基础方法INSERT① insert② insertSelec

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加