草庐IT

CSS过渡动画

2764150442 2023-04-04 原文

css中实现动画有两种方式:transition过渡动画、 animation自定义动画。

transition 是 css3 新增的⼀个功能,可以实现元素不同状态间的平滑过渡(当元素从⼀个状态进⼊到另⼀个状态时),经常⽤来制作⼀些动画效果。

之前:元素 -> 元素:hover 状态直接切换,从开始状态到结束状态,瞬间完成,中间过程⼏乎不可⻅。

过渡:从开始状态到结束状态的中间过程可以查看

格式:

transition:过渡的属性 完成时间(s) 运动曲线 延迟时间

transition:all 3s(1s=1000ms) linear 0s;

transition 包含以下四个属性:

transition-property 过渡属性。如果希望所有的属性都发⽣过渡,就使⽤all

transition-duration 过渡的持续时间,单位是s或者ms

transition-timing-function 运动曲线。属性值取值:

ease 慢速开始,然后变快,然后慢速结束的过渡效果(默认 cubic-bezier(0.25,0.1,0.25,1))

linear 线性,以相同速度开始至结束的过渡效果(cubic-bezier(0,0,1,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 函数中定义自己的值,https://cubic-bezier.com/

transition-delay 默认是0,单位为s,过渡延迟。多⻓时间后再执⾏这个过渡动画。

transition-duration 这个属性需要首先设置,否则时长为 0,就不会产生过渡效果。

1.圆过渡

<style>
        .div-1{
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background-color: aqua;
            transition: all 3s;
            transition-timing-function: steps(3000,start);
        }
        .div-1:hover{
            background-color: rgb(21, 255, 0);
            width: 400px;
            height: 400px;
            border-radius: 0%;
        }
    </style>

 

 

2.钟表秒针

<style>
        .clock{
            background: url(img/clock.png);
            border-radius: 50%;
            width: 284px;
            height: 284px;
            position: relative;
        }
        .clock::before{
            content: "";
            width: 20px;
            height: 20px;
            background-color: black;
            transform: translate(-50%,-50%);
            top: 50%;
            left: 49.5%;
            position: absolute;
            border-radius: 50%;
        }
        .clock::after{
            content: "";
            width: 3px;
            height: 110px;
            background-color: black;
            position: absolute;
            left: 49.8%;
            top: 50%;
            transform: translate(-50%,-100%);
            border-radius: 70%;
            transform-origin: bottom;
            animation: rotate360 60s steps(60) infinite;
        }
        @keyframes rotate360 {
            to {
                transform: translate(-50%, -100%) rotate(360deg);
            }
        }
        /* .clock:hover::after{
            transform: translateX(-50%) rotate(360deg);
        } */
    </style>

 

 3.圆过渡动画

 <style>
        .div-1{
            width: 300px;
            height: 300px;
            background-color: royalblue;
            border-radius: 50%;
            /* 应用动画 */
            animation-name: div_animate;    /*制定动画名称*/
            animation-duration: 2s;         /*动画持续时间*/
             animation-fill-mode: forwards; /*动画填充模式,forwards作用是将动画的样式停留在最后一个 */
            animation-delay: 2s;           /*动画延迟的时间,当值为负数时表示动画已经执行了多长时间*/
            animation-direction: alternate;     /*规定是否应该轮流反向播放动画。*/
            animation-iteration-count: infinite;    /*规定动画的速度曲线。*/
            animation-timing-function: cubic-bezier(.97,.08,.35,.72);/*速度*/
        }

        /* 定义动画规则 */
        @keyframes div_animate{
            from{
                background-color:royalblue;
                margin-left: 0px;
            }
            to{
                background-color: brown;
                margin-left: 500px;
            }
        }
    </style>

 

有关CSS过渡动画的更多相关文章

  1. ruby - capybara field.has_css?匹配器 - 2

    我在MiniTest::Spec和Capybara中使用以下规范:find_field('Email').must_have_css('[autofocus]')检查名为“电子邮件”的字段是否具有autofocus属性。doc说如下:has_css?(path,options={})ChecksifagivenCSSselectorisonthepageorcurrentnode.据我了解,字段“Email”是一个节点,因此调用must_have_css绝对有效!我做错了什么? 最佳答案 通过JonasNicklas得到了答案:No

  2. css - 用 watir 检查标签类? - 2

    我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes

  3. Unity 3D 制作开关门动画,旋转门制作,推拉门制作,门把手动画制作 - 2

    Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u

  4. ruby-on-rails - Assets 管道损坏 : Not compiling on the fly css and js files - 2

    我开始了一个新的Rails3.2.5项目,Assets管道不再工作了。CSS和Javascript文件不再编译。这是尝试生成Assets时日志的输出:StartedGET"/assets/application.css?body=1"for127.0.0.1at2012-06-1623:59:11-0700Servedasset/application.css-200OK(0ms)[2012-06-1623:59:11]ERRORNoMethodError:undefinedmethod`each'fornil:NilClass/Users/greg/.rbenv/versions/1

  5. ruby-on-rails - Rails - 理解 application.js 和 application.css - 2

    rails新手。只是想了解\assests目录中的这两个文件。例如,application.js文件有如下行://=requirejquery//=requirejquery_ujs//=require_tree.我理解require_tree。只是将所有JS文件添加到当前目录中。根据上下文,我可以看出requirejquery添加了jQuery库。但是它从哪里得到这些jQuery库呢?我没有在我的Assets文件夹中看到任何jquery.js文件——或者直接在我的整个应用程序中没有看到任何jquery.js文件?同样,我正在按照一些说明安装TwitterBootstrap(http:

  6. css - Rails 4.1 和 Bootstrap 3 字形图标不工作 - 2

    我正在尝试消除使用Bootstrap3的Rails4元素中的glyphicon错误。我没有使用任何Bootstrapgem将其添加到Assets管道中。我手动将bootstrap.css和bootstrap.js添加到各自的app/assets目录下,分别添加到application.css和application.js什么的我现在在网络浏览器的控制台中看到以下内容:GEThttp://localhost:3000/fonts/glyphicons-halflings-regular.woff404(NotFound)localhost/:1GEThttp://localhost:30

  7. css - rails 萨斯 : variables are not passed with @import - 2

    我有一个使用twitterbootstrap和sass的Rails元素。scss文件结构化到文件夹中,所以我有更好的概述。现在我想为包含我的颜色等的全局变量定义一个文件,并将这些值传递给其他文件,这样我就有更少的冗余代码。虽然所有代码都已正确导入和应用,变量不起作用。这是当前的设置:样式表/application.css.scss/**=require_self*=require_tree*//*stylesheets/||–base/||–_reset.scss#Reset/normalize||–_typography.scss#Typographyrules||–componen

  8. css - Jekyll 和自定义 CSS - 2

    有没有一种方法可以在jekyll站点中包含自定义css标签,同时将markdown用于入口文件?例如,当我想突出显示某个段落时? 最佳答案 Markdown和YAMLFrontMatter都内置了这个。但你可以自己制作。比如说,您有foo.css想要包含在某些帖子中。在_posts/2013-02-03-higligting-foo.markdown中:---css:footitle:"DrupalImagecachesecurityvulnarabilitywithDDOSattackexplained"tags:[drupal,

  9. LVGL V8动画 - 2

    动画/*INITIALIZEANANIMATION 初始化一个动画*-----------------------*/lv_anim_ta;lv_anim_init(&a);/*MANDATORYSETTINGS 必选设置*------------------*//*Setthe"animator"function 设置“动画”功能*/lv_anim_set_exec_cb(&a,(lv_anim_exec_xcb_t)lv_obj_set_x);/*Setthe"animator"function*/lv_anim_set_var(&a,obj);/*Lengthoftheanim

  10. css - 检测到 Sass 更改但 style.css 仅在我保存时每 5 到 7 次被覆盖 - 2

    我在一台Windows764位机器上使用Sass和Ruby(最新版本),我正在我的家庭服务器上处理一个共享文件夹。(但是,我不得不承认问题本身也出现在服务器上,因为我试图安装Ruby并直接-watch服务器上的文件)。问题如下:如果我第一次保存,检测到变化,我的style.css被直接覆盖。之后,我总是需要保存多达7次才能覆盖style.css。每次都会检测到更改,但不会编译任何内容。这是一个屏幕:>>>Sassiswatchingforchanges.PressCtrl-Ctostop.overwritestyle.css>>>Changedetectedto:E:/Websites

随机推荐