我可以用CSS3制作类似的动画吗?

4

我正在开发一款网站,现在需要制作一个与http://www.elitemodel.fr/相同的介绍动画。

当这个网站加载页面时,标志和背景会向左滑动。我的客户想要这种效果在他的网站上。

目前,我已经创建了一个intro.php的网页,并使用以下HTML代码:

<div class="intro">
    <div class="logo-intro"></div><!-- /.logo logo-intro -->
</div><!-- /.intro -->
<div class="black_overlay"></div><!-- /.logo logo-intro -->

我正在尝试用CSS3和一点JavaScript来完成这个。

在HTML之后,这是我的动画CSS代码:

.intro,
.intro .logo-intro {
    overflow: hidden;
   -moz-animation: slide 2s ease 1.5s forwards;
   -webkit-animation: slide 2s ease 1.5s forwards;
   -o-animation: slide 2s ease 1.5s forwards;
   -ms-animation: slide 2s ease 1.5s forwards;
    animation: slide 2s ease 1.5s forwards;
}

@-moz-keyframes slide /* Firefox */
    {
        from {width: 100%; }
        to {width: 0;}
    }

@-webkit-keyframes slide /* Safari and Chrome */
    {
        from {width: 100%;}
        to {width: 0;}
    }

@-o-keyframes slide /* Opera */
    {
        from {background: white;}
        to {background: black;}
    }

@-ms-keyframes slide /* IE10 */
    {
        from {width: 100%;}
        to {width: 0;}
    }

@keyframes slide
    {
        from {width: 100%;}
        to {width: 0;}
    }

}

.logo-intro  {
    -webkit-animation: logo 1s;  /* Chrome, Safari, Opera */
    -webkit-animation-iteration-count: 2;  /* Chrome, Safari, Opera */
    -webkit-animation-fill-mode: forwards;  /* Chrome, Safari, Opera */
    animation: logo 1s;
    animation-iteration-count: 2;
    animation-fill-mode: forwards;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes logo {
    from {top: 50%;}
    to {left: -99999px;}
}

@keyframes logo {
    from {top: 50%;}
    to {left: -99999px;}
}

动画结束后,我使用JavaScript将intro.php重定向到主页。
// Your application has indicated there's an error
window.setTimeout(function(){
// Move to a new location or you can do something else
var url = "http://www.gaelscalpaesthetics.com/accueil";    
$(location).attr('href',url);
}, 4000);

这个功能可以正常工作,但我如何在不重定向的情况下进行动画效果呢?

祝好,


在JavaScript中,您可以清楚地看到在4秒(4000)后用户将被重定向到给定的“url”。如果您不想这样做,只需删除或注释掉代码即可。 - Franco
2个回答

1
尝试像这样的东西

DEMO

body, html {
  max-width: 100%;
  overflow-x: hidden;
}

.logo,
.black-bg {
  display: flex;
  min-height: 100vh;
  min-width: 100vw;
  position: fixed;
  justify-content: center;
  align-items: center;
  font-size: 50px;
}

.logo {
  z-index: 1;
  background: white;
  animation: animateLogo 2s ease-in-out 1.3s forwards;
}

.black-bg {
  background: black;
  z-index: 2;
  transform: translateX(100vw);
  animation: animateBlackBg 1.5s ease-in-out 1.5s forwards;
}

.content {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100%;
}

.content img {
  flex: 1;
  padding: 20px;
}

@keyframes animateLogo {
  80% {
    transform: translateX(-100vw);
    opacity: 1; 
  }

  100% {
    transform: translateX(-100vw);
    opacity: 0; 
  }
}

@keyframes animateBlackBg {
  40% {
    transform: translateX(0);
    opacity: 1;
  }

  80% {
    transform: translateX(0);
    opacity: 1;
  }

  100% {
    transform: translateX(0);
    opacity: 0;
  }

}

<div class="logo">LOGO</div>
<div class="black-bg"></div>

<div class="content">
  <img src="http://placehold.it/500x900">
  <img src="http://placehold.it/500x900">
</div>

谢谢你的帮助。代码运行得很好。这是我的第一个解决方案。 我按照你的方法将intro div放置在首页上作为覆盖层,但每次进入首页时动画都会加载。动画只应在首页加载一次。 - Yordan Kostadinov
很高兴能帮到你,我建议你针对那个具体的问题提出另一个问题。此外,如果这个答案或其他任何答案解决了你的问题,请将其标记为已接受。 - Nenad Vracar

0

简单来说,你可以把你的代码放在主页上,在页面加载时运行它,在动画结束后显示你的内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接