C3动画及常用属性

C3动画及常用属性

  • 动画的制作步骤:
    1. 定义动画
    2. 调用动画
一、定义动画
  • 定义动画用keyframes关键字。

      @keyframes 动画名称 {
      	/* 动画开始时的状态 */
      	0% {
      		height: 50px
      	}
    
      	50% {
      		height: 70px
      	}
      	/* 动画结束时的状态 */
      	100% {
      		height: 100px
      	}
    
      }
    
  • 其中 0% 50% 100% 被称为动画序列。

二、调用动画
  • 哪个元素要使用此动画直接通过动画名称调用。

  • 调用动画所用的关键字为:animation-name

      animation-name: 动画名称;
      /* 调用动画后,还必须给该动画完成一个周期所花费的时间(单位为秒或毫秒) */
      animation-duration:持续时间;
    

一个最简单的动画案例如下:

<style>

    /* 1. 定义动画 */
    @keyframes donghua {

		/* 动画开始时的状态 */
		0% {
			height: 50px
		}

		50% {
			height: 100px
		}
		/* 动画结束时的状态 */
		100% {
			height: 200px
		}

	}
    
    div {
        width: 100px;
        height: 100px;
		margin: 100px auto;
        background-color: #00fdad;

        /* 2. 调用动画 */
        animation-name: donghua;
        /* 动画持续时间 */
        animation-duration: 1.5s;
    }
</style>

<div></div>
  • 效果如下:
    在这里插入图片描述
动画的常用属性
属性含义
@keyframes定义动画
animation所有动画属性的简写属性,除了animation-play-state属性。
animation-name(必须写)规定@keyframes动画的名称。
animation-duration(必须写)规定动画完成一个周期所花费的秒或毫秒 , 默认是0。
animation-timing-function规定动画的速度曲线,默认是"ease"。
animation-delay规定动画何时开始,默认是0
animation-iteration-count规定动画被播放的次数,默认是1,还有infinite(循环)
animation-direction规定动画是否在下一-周期逆向播放,默认是"normal ",alternate逆播放
animation-play-state规定动画是否正在运行或暂停。默认是"running",还有"paused"(暂停)。
animation-fill-mode规定动画结束后状态,保持forwards,回到起始backwards

动画属性的复合写法:

animation :动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 动画起始或者结束的状态;

animation:动画名称持续时间运动曲线何时开始播放次数是否反方向动画起始或者结束的状态;
animation:donghua(必填)1.5s(必填)ease(默认)0(默认)1(默认),infinite(循环)normal(默认),alternate(逆向播放)backwards(回到起始位置),forwards(停在结束位置)

animation: myfirst 5s linear 2s infinite alternate;

  • 简写属性里面不包含animation-play-state(暂停)

  • 暂停动画: animation-play-state: puased; 经常和hover配合使用

  • 想要动画走回来,而不是直接跳回来: animation-direction : alternate; (逆播放)

  • 盒子动画结束后,停在结束位置: animation-fill-mode : forwards; (保持在结束位置)

  • 速度曲线表格

含义
linear动画从头到尾的速度是相同的。匀速
ease默认。动画以低速开始,然后加快,在结束前变慢。
ease-in动画以低速开始。
ease-out动画以低速结束。
ease-in-out动画以低速开始和结束。
steps()指定了时间函数中的间隔数量(步长)
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
您可以使用C3.js库中的transition动画函数实现摇铃铛效果。以下是一个实现的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>C3.js 摇铃铛效果</title> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.18/c3.min.css"> </head> <body> <div id="chart"></div> <script src="https://d3js.org/d3.v5.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.18/c3.min.js"></script> <script> var chart = c3.generate({ bindto: '#chart', data: { columns: [ ['data', 30] ], type: 'gauge' }, gauge: { width: 15, min: 0, max: 100, units: 'value', label: { show: false } }, color: { pattern: ['#FF0000', '#F97600', '#F6C600', '#60B044'], threshold: { values: [30, 60, 90, 100] } } }); function shakeBell() { chart.load({ columns: [ ['data', 30] ], type: 'gauge', done: function() { chart.internal.config.gauge_label_show = false; d3.select('.c3-gauge-value') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, 10)') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, -10)') .transition() .duration(500) .ease(d3.easeElasticOut) .attr('transform', 'translate(0, 0)'); } }); } setInterval(shakeBell, 3000); </script> </body> </html> ``` 在此示例中,我们使用了C3.js的仪表图(gauge)类型,然后通过定时调用shakeBell()函数来实现摇铃铛的效果。在shakeBell()函数中,我们先重新加载了一个值为30的数据列,并通过transition函数来实现振动动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿年、嗯啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值