分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

CSS3的 transition 属性

发布时间:2023-09-06 02:01责任编辑:熊小新关键词:CSS

CSS3的 transition 属性用于状态过度效果!

1、语法:

1 transition: property duration timing-function delay;2 -moz-transition: property duration timing-function delay;3 -webkit-transition: property duration timing-function delay;4 -o-transition: property duration timing-function delay;

上以语法兼容各浏览器。

2、transition含有四个部份设置,各部份设置如下:

a) property :规定设置过渡效果的 CSS 属性的名称,可选值如下:

none  没有属性会获得过渡效果。
all【默认值】所有属性都将获得过渡效果。
property定义应用过渡效果的 CSS 属性名称列表,列表以逗号分隔,比如: width,height

 比如: transition: width 3s; 只让宽度产生动画过渡效果,其它属性不产生效果。

b) duration:规定完成过渡效果需要多少秒或毫秒,比如:transition: all 3s; 表示3秒完成过渡效果。

c) timing-function :规定速度效果的速度曲线,可选值如下:

linear规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。
ease规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。
ease-in规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。
ease-out规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。
ease-in-out规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。
cubic-bezier(n,n,n,n)在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。  

  

d) delay:定义过渡效果何时开始,比如: transition: width 3s linear 5s;

以下是一代简易代码演示:

 1 <!doctype html> 2 <html> 3 <head> 4 ????<script src="js/jquery.js"></script> 5 ????<style> 6 ????????.a { 7 ????????????width:100%; 8 ????????????height:200px; 9 ????????????transition:all 3s ease-in;10 ????????????background:#03F;11 ????????}12 ????????.c {13 ????????????width:300px;14 ????????}15 ????????.a:hover {16 ????????????height:400px;17 ????????}18 ????</style>19 </head>20 21 <body>22 <div class="a">23 </div>24 25 <p>单击页面,使宽度缩小</p>26 <p>移到红色区域,使高度变大</p>27 <script>28 ????$(document).click(function(){29 ????????$(‘.a‘).addClass(‘c‘);30 ????});31 </script>32 </body>33 </html>

CSS3的 transition 属性

原文地址:https://www.cnblogs.com/wm218/p/9242744.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved