简体   繁体   English

如何将@keyframes动画仅应用于背景?

[英]How would I apply my @keyframes animation to just my background?

I have an advert container using grid and I've applied a @keyframes animation to it and it looks pretty cool! 我有一个使用网格的广告容器,并且对它应用了@keyframes动画,它看起来很酷! However, I'd like the image itself to move and not the text in the foreground. 但是,我希望图像本身可以移动,而不是前景中的文本。

At the moment I'm moving the entire container which is obviously what needs to change but I can't figure out where I need to go from here. 目前,我正在移动整个容器,这显然是需要更改的,但是我不知道该从哪里去。

 advert { grid-area: advert; background-image: url(./mi-vr-5.jpg); background-position-x: 50%; background-position-y: 50%; background-size: 1000px; } .righttoleft { animation-name: righttoleft; animation-duration: 3s; } @keyframes righttoleft { 0% { transform: translateX(100%); } 100% { transform: translateX(0); } } 
 <advert class="righttoleft"> <div class="title-shift"> <h1 class="title">bla bla bla</h1> <h3 class="title-shift-h3">bla bla bla</h3> <p class="title-shift-h3">bla bla bla.</p> </div> </advert> 

You can do it like below, You need to use background position instead of transform translate, and you're done! 您可以像下面那样进行操作,您需要使用背景位置而不是变换翻译,然后就可以完成!

 .righttoleft { -moz-animation: righttoleft 3s infinite alternate; -o-animation: righttoleft 3s infinite alternate; -webkit-animation: righttoleft 3s infinite alternate; animation: righttoleft 3s infinite alternate; grid-area: advert; background-image: linear-gradient(to right, red, yellow); background-position: 0% 0%; background-size: 1000px; float: left; width: 100%; } @keyframes righttoleft { 0% { background-position: 0% 0%; } 100% { background-position: 100% 100%; } } 
 <advert class="righttoleft"> <div class="title-shift"> <h1 class="title">bla bla bla</h1> <h3 class="title-shift-h3">bla bla bla</h3> <p class="title-shift-h3">bla bla bla.</p> </div> </advert> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM