<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style media="screen">
.basic{
background-color: red;
/* width: 300px;
height: 300px; */
} @keyframes animate1
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-moz-keyframes animate1 /* Firefox */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-webkit-keyframes animate1 /* Safari 和 Chrome */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-o-keyframes animate1 /* Opera */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} .animate2 { animation: animate1 5s;
-moz-animation: animate1 5s; /* Firefox */
-webkit-animation: animate1 5s; /* Safari 和 Chrome */
-o-animation: animate1 5s; /* Opera */ } </style>
</head>
<body>
<div class="basic" id="div1">
hello world.
</div> <button type="button" name="button">点击应用动画</button> <script type="text/javascript">
const btn = document.getElementsByName('button')[0];
const div = document.getElementById("div1");
btn.addEventListener('click', ()=>{
console.log("点击按钮。。。");
if(div.classList.contains("basic")){
div.classList.remove("basic");
}
div.classList.add("animate2");
});
</script>
</body>
</html>

1. 使用@keyframes定义一个动画效果。

 @keyframes animate1
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-moz-keyframes animate1 /* Firefox */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-webkit-keyframes animate1 /* Safari 和 Chrome */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
} @-o-keyframes animate1 /* Opera */
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
}

2.将动画效果先绑定到css类上。

 .animate2 {

   animation: animate1 5s;
-moz-animation: animate1 5s; /* Firefox */
-webkit-animation: animate1 5s; /* Safari 和 Chrome */
-o-animation: animate1 5s; /* Opera */ }

3.将动画效果应用到指定的元素上。

const btn = document.getElementsByName('button')[0];
const div = document.getElementById("div1");
btn.addEventListener('click', ()=>{
console.log("点击按钮。。。");
if(div.classList.contains("basic")){
div.classList.remove("basic");
}
div.classList.add("animate2");
});

当点击按钮时,就会将定义的动画效果应用到div上。

css3 animation动画使用的更多相关文章

  1. css3 animation动画特效插件的巧用

    这一个是css3  animation动画特效在线演示的网站 https://daneden.github.io/animate.css/ 下载 animate.css文件,文件的代码很多,不过要明白 ...

  2. css3 animation动画技巧

    一,css3 animation动画前言 随着现在浏览器对css3的兼容性越来越好,使用css3动画来制作动画的例子也越来越广泛,也随着而来带来了许多的问题值得我们能思考.css3动画如何让物体运动更 ...

  3. CSS3 animation动画

    CSS3 animation动画 1.@keyframes 定义关键帧动画2.animation-name 动画名称3.animation-duration 动画时间4.animation-timin ...

  4. CSS3 animation 动画

    今天看到一个很酷的logo看了下他用的是animation 动画效果,就拿来做例子 浏览器支持 Internet Explorer 10.Firefox 以及 Opera 支持 animation 属 ...

  5. css3 animation(动画)笔记

    在开始介绍Animation之前我们有必要先来了解一个特殊的东西,那就是"Keyframes",我们把他叫做“关键帧”,玩过flash的朋友可能对这个东西并不会陌生.下面我们就一起 ...

  6. css3 animation 动画属性简介

    animation 动画属性介绍 animation 属性是一个简写属性,用于设置动画属性: 1. animation-name----规定需要绑定到选择器的 keyframe 名称. 语法:anim ...

  7. css3 animation动画事件

    当使用css3时,会遇到利用@keyframes来定义动画事件,利用以下3个事件,能够捕捉当前元素的动画: AnimationEnd //动画结束时 AnimationStart  //动画開始 An ...

  8. CSS3 animation动画,循环间的延时执行时间

    如下代码,其中的delay值为3s,但是animation按现在的规则,这个delay是指动画开始前的延时,在动画循环执行间,这个delay是不生效的. .item{ webkit-animation ...

  9. 关于css3 Animation动画

    在介绍animation之前有必要先来了解一个东西,那就是“keyframes”,我们把他叫做“关键帧”: 在使用transition制作一个简单的transition效果时,包括了初始属性,最终属性 ...

随机推荐

  1. UGUI 锚点设置为四方扩充模式然后设置局部坐标为0将出现什么问题

    UGUI 锚点设置为四方扩充模式然后设置局部坐标为0将出现什么问题? 情形:按钮A挂在主画布上.四方扩充模式.A的中心和画面中心不重合. 这时候用代码设置A.localPosition = new V ...

  2. MVC-READ4

    internal BuildManagerCompiledView(ControllerContext controllerContext, string viewPath, IViewPageAct ...

  3. dsm 黑 离线转码 备忘

    6.2以后不行 我用的是 DS3617_6.17-15284 进入下载安装文件和工具 1安装 .套件来源增加 packages.synocommunity.comb.设置信任级别为任何发行者 c.找到 ...

  4. jsp脚本语法

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. Vertex color blending & UV tiling

    [Vertex color blending & UV tiling] 1.GemotryData控件用于代码顶点数据,如网格中的Vertex Color(下左图),UV Coord(下右图) ...

  6. python实例、类方法、静态方法

    [python实例.类方法.静态方法] 参考:http://blog.163.com/yang_jianli/blog/static/161990006201122411586729/

  7. PowerDesigner如何导出建表sql脚本(转)

    1 按照数据库类型,切换数据库. Database-> Change Current DBMS... 2 生成sql脚本 Database -> Database Generation 的 ...

  8. IDEA07 快捷键统计插件之Key Promoter X

    1 官方介绍 该插件会统计你鼠标操作的次数,然后在一个窗口中展示出来 https://plugins.jetbrains.com/plugin/9792-key-promoter-x 2 下载.安装. ...

  9. sqlserver查询存储过程的创建时间及最后修改时间

    select  [name] ,create_date ,modify_date FROM  sys.all_objects where  type_desc = N'SQL_STORED_PROCE ...

  10. Memcached在Linux环境下的使用详解http://blog.51cto.com/soysauce93/1737161

    大纲 一.什么是memcached 二.memcached特性 三.memcached存储方式 四.memcached安装与配置 五.memcached结合php 六.Nginx整合memcached ...