CSS动画。但Chrome上没有任何事情发生。显示正常标题

问题描述 投票:0回答:2

试图做动画。但Chrome上没有任何事情发生。显示正常标题。

*{
margin: 0;
height: 0;
box-sizing: border-box;
}

body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
padding: 30px;
}

header{
height: 95vh;
background-image: linear-gradient(to right bottom,rgba(126,213,111,0.8), rgba(40,180,131,0.8)),url(../img/hero.jpg);
background-size: cover;
background-position: top;
position: relative;

clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
}

.text-box{
position: absolute;
top: 30%;
left: 50%;
transform: translate(-40%,-50%);
}

.logo-box{
position: absolute;
top: 40px;
left: 40px;

}

.logo{
height: 35px;
}

.heading-primary{
color: #fff;
text-transform: uppercase;
}

.heading-primary-main{
letter-spacing: 35px;
font-weight: 400;
font-size: 60px;

animation-name: moveInLeft;
animation-duration: 4s;
animation-iteration-count: 3;
/*animation-delay: 3s;*/
}

.heading-primary-sub{
display: block;
letter-spacing: 17.5px;
font-weight: 700;
font-size: 20px;
}

@-webkit-keyframes moveInLeft{
0% {
opacity: 0;
transform: translateX(-100px);
}
80%{
transform: translateX(10px);
}
100%{
opacity: 1;
transform: translateX(0);
}
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">

        <link rel="stylesheet" href="css/icon-font.css">
        <link rel="stylesheet" href="css/style.css">
        <link rel="shortcut icon" type="image/png" href="img/favicon.png">

        <title>Natours | Exciting tours for adventurous people</title>
    </head>
    <body>
        <header class='header'>
           <div class='logo-box'>
            <img src='img/logo-white.png' alt='logo' class='logo'>
        </div>

        <div class='text-box'>
            <h1 class="heading-primary">
            <span class='heading-primary-main'>Outdoors</span>
            <span class='heading-primary-sub'>is where life happens</span>
        </h1>
        </div>

        </header>
    </body>
</html>
    
    

我想执行动画,使得标题从左向右移动但是没有发生任何事情,因为标题按原样显示。我用@-webkit-keyframes仍然没有发生任何事情。二手@keyframes什么都没发生。是浏览器的问题(Chrome)?请有人帮帮我吗? CSS中的这个动画我最近开始学习,但这个错误确实让人无法进一步学习。

html css
2个回答
2
投票

有了这些变化,它对我来说非常好 - :

.heading-primary {
  animation: play 4s steps(10) infinite;
}

@keyframes play {
  from {
    transform: translate(-100px);
  }
  to {
    transform: translate(0px);
  }
}

0
投票

而不是transform你可以使用margin-left

*{
margin: 0;
height: 0;
box-sizing: border-box;
}

body{
font-family: "Lato", sans-serif;
font-weight: 400;
font-size: 16px;
line-height: 1.7;
color: #777;
padding: 30px;
}

header{
height: 95vh;
background-image: linear-gradient(to right bottom,rgba(126,213,111,0.8), rgba(40,180,131,0.8)),url(../img/hero.jpg);
background-size: cover;
background-position: top;
position: relative;

clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
}

.text-box{
position: absolute;
top: 30%;
left: 50%;
transform: translate(-40%,-50%);
}

.logo-box{
position: absolute;
top: 40px;
left: 40px;

}

.logo{
height: 35px;
}

.heading-primary{
color: #fff;
text-transform: uppercase;
}

.heading-primary-main{
letter-spacing: 35px;
font-weight: 400;
font-size: 60px;

animation-name: moveInLeft;
animation-duration: 4s;
animation-iteration-count: 3;
/*animation-delay: 3s;*/
}

.heading-primary-sub{
display: block;
letter-spacing: 17.5px;
font-weight: 700;
font-size: 20px;
}

@-webkit-keyframes moveInLeft{
0% {
opacity: 0;
margin-left: -100%;
}
100%{
opacity: 1;
margin-left: 0;
}
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">

        <link rel="stylesheet" href="css/icon-font.css">
        <link rel="stylesheet" href="css/style.css">
        <link rel="shortcut icon" type="image/png" href="img/favicon.png">

        <title>Natours | Exciting tours for adventurous people</title>
    </head>
    <body>
        <header class='header'>
           <div class='logo-box'>
            <img src='img/logo-white.png' alt='logo' class='logo'>
        </div>

        <div class='text-box'>
            <h1 class="heading-primary">
            <span class='heading-primary-main'>Outdoors</span>
            <span class='heading-primary-sub'>is where life happens</span>
        </h1>
        </div>

        </header>
    </body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.