背景渐变动画

背景渐变动画(纯css+html)

<!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>背景渐变动画</title>
    <link rel="stylesheet" href="style.css">
    <script src="JavaScript.js" type="text/javascript"></script>
</head>
<body>
  <div id="bg">
  	<h2>背景渐变动画</h2>
  </div>
</body>
</html>
* {
  margin: 0;
  padding: 0;
}
#bg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  animation: bg 10s infinite linear;  /* 使用动画:动画时长10s,循环播放,匀速播放 */
}
@keyframes bg  /* 定义动画 */
{
    0%   {background: #f3ffd9}
    25%  {background: #cadda0}
    50%  {background: #5e6f4d}
    75%  {background: #cadda0}
    100% {background: #f3ffd9}
}

点击监听控制背景渐变动画(html+css+js)

<!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>背景渐变动画</title>
    <link rel="stylesheet" href="style.css">
    <script src="JavaScript.js" type="text/javascript"></script>
</head>
<body>
  <div id="bg">
    <ul>
      <li class="pink" onclick="pink()">少女粉</li>
      <li class="orange" onclick="orange()">活力橙</li>
      <li class="blue" onclick="blue()">星空蓝</li>
    </ul>
  </div>
</body>
</html>
* {
  margin: 0;
  padding: 0;
}
#bg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
ul {
  list-style: none;
  width: 100%;
  height: 80px;
  margin-top: 50px;
  display: flex;
  justify-content: space-evenly;
}
li {
  width: 200px;
  height: 80px;
  line-height: 80px;
  text-align: center;
  border-radius: 20px;
}
li:hover {
  box-shadow: 15px 15px 20px #a7a7a7;
}
.pink {
  background-image: linear-gradient(#ee9ca7, #ffdde1);
}
.orange {
  background-image: linear-gradient(#fdc830, #f73335);
}
.blue {
  background-image: linear-gradient(#000046, #1cb5e0);
}

@keyframes bg1
{
    0%   {background: #ffdde1;}
    50%  {background: #ee9ca7;}
    100% {background: #ffdde1;}
}
@keyframes bg2
{
    0%   {background: #fdc830;}
    50%  {background: #f73335;}
    100% {background: #fdc830;}
}
@keyframes bg3
{
    0%   {background: #000046;}
    50%  {background: #1cb5e0;}
    100% {background: #000046;}
}
function pink() {
    document.getElementById('bg').style.animation="bg1 5s infinite linear";
}

function orange() {
    document.getElementById('bg').style.animation="bg2 5s infinite linear";
}

function blue() {
    document.getElementById('bg').style.animation="bg3 5s infinite linear";
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

呦呀

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

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

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

打赏作者

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

抵扣说明:

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

余额充值