本篇文章主要向大家介紹如何使用css製作簡單的動畫,感興趣的小夥伴參考下.
案例一:
<!DOCTYPE html><html><head><meta charset="utf-8"> <title>php中文網</title> <style> div{width:100px;height:100px;background:red;animation:myfirst 5s;-moz-animation:myfirst 5s; /* Firefox */-webkit-animation:myfirst 5s; /* Safari and Chrome */-o-animation:myfirst 5s; /* Opera */}@keyframes myfirst{0% {background:red;}25% {background:yellow;}50% {background:blue;}100% {background:green;}}@-moz-keyframes myfirst /* Firefox */{0% {background:red;}25% {background:yellow;}50% {background:blue;}100% {background:green;}}
案例二:
<!DOCTYPE html><html><head><meta charset="utf-8"> <title>php中文網</title> <style> div{width:100px;height:100px;background:red;position:relative;animation:myfirst 5s;-webkit-animation:myfirst 5s; /* Safari and Chrome */}@keyframes myfirst{0% {background:red; left:0px; top:0px;}25% {background:yellow; left:200px; top:0px;}50% {background:blue; left:200px; top:200px;}75% {background:green; left:0px; top:200px;}100% {background:red; left:0px; top:0px;}}@-webkit-keyframes myfirst /* Safari and Chrome */{0% {background:red; left:0px; top:0px;}25% {background:yellow; left:200px; top:0px;}50% {background:blue; left:200px; top:200px;}75% {background:green; left:0px; top:200px;}100% {background:red; left:0px; top:0px;}}</style></head><body>
相關推薦:
PHP全站開發工程師-擴充之CSS動畫和animate.css和wow.js
vue的css動畫
用css實現css動畫的暫停與播放功能教程