CSS进阶-盒子与动画

CSS进阶-盒子与动画



前言

CSS3动画美轮美奂,在特效上提供了比JS更为流畅的体验,搭配网页千姿百态的颜色,为网页的鲜活提供了更为动人的美感,无论是个人开发还是商业性网站,有效组合CSS3动画的使用,会让用户获得更为有科技感的动效体验 。
本文介绍CSS3动效关键帧的使用以及类似jQuery提供的过渡效果概念


Chapter04 CSS3动画

1. Animation动画


1.1 关键帧

关键帧:是通过CSS的@keyframes属性,预先定义出的每个阶段的动画特征

1.2 定义关键帧

1.2.1 定义示例

/* 示例1 */
@keyframes myfirst
{
    
    from {
   background: red;}
    to{
   background: yellow;} 
}
/* 示例2 */
@keyframes mymove
{
   
    0%{
   background:olive; left:0px;   top:100px;}
    50%{
   background:teal; left:350px; top:100px;transform:rotate(-180deg);}
    100% {
   background: aqua; left:600px; top:100px;}
}

1.2.2 效果

示例1变换效果 示例2变换效果
在这里插入图片描述 示例2:定义关键帧

1.2.3 完整案例


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>6-1 Animation 动画</title>
    <link rel="stylesheet" href="./css/common.css">
    <style type="text/css">
        .backgroundchange{
     
            width: 600px;
            height: 180px;
            margin: 20px;
            border: 2px solid #c9deec;
            border-radius: 20px;
        }
        .areaheight{
     height: 355px;}
        .colorbox-1,.colorbox-2,.colorbox-3{
     
            width: 100px;
            height: 100px;
            font:900 16px/100px Cmabria,'楷书';
            color: #FFF;
            text-align: center;
            margin: 40px;
            position: relative;
            background: transparent;
            border-radius: 10px;
        }

        .colorbox-1{
     
            animation: boxbackchange 3s infinite;
            -o-animation: boxbackchange 3s infinite;        /*Opera*/
            -moz-animation: boxbackchange 3s infinite;      /*Firefox*/
            -webkit-animation: boxbackchange 3s infinite;   /*safari and Chrome*/
        }
        @keyframes boxbackchange{
     
            from{
     background: #FB8B05; left: 0px;top: 0px;}
            to{
     background: #00ffff; left: 400px; top: 0px;}
        }
        /* 示例1 */
        @keyframes myfirst
        {
      
            from {
     background: red;}
            to{
     background: yellow;} 
        }

        .colorbox-2{
     
            animation: boxrotate 3s infinite;
            -o-animation: boxrotate 3s infinite;        /*Opera*/
            -moz-animation: boxrotate 3s infinite;      /*Firefox*/
            -webkit-animation: boxrotate 3s infinite;   /*safari and Chrome*/
        }
        @keyframes boxrotate{
     
            0% {
     background: #808000; left: 0px; top:0px}
            50% {
     background: #008080; left: 200px; top:0px;transform: rotate(-180deg);}
            100% {
     background: #00ffff; left: 400px; top:0px}
        }
        /* 示例2 */
        @keyframes mymove
        {
     
            0%{
     background:olive; left:0px;   top:100px;}
            50%{
     background:teal; left:350px; top:100px;transform:rotate(-180deg);}
            100% {
     background: aqua; left:600px; top:100px;}
        }

        .colorbox-3{
     
            animation: boxroundruning 10s infinite;
            -o-animation
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值