仅对背景使用关键帧旋转
use keyframes rotate for the background only
你好,我有一张带有背景图片的图片,我只需要为背景制作旋转动画,但动画适用于它们。
这是我的 css 代码:
.to-rotate .img{
-webkit-animation-name: rotate;
-webkit-animation-duration:6s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-moz-animation-name: rotate;
-moz-animation-duration:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-timing-function:linear;
}
@-webkit-keyframes rotate {
from {-webkit-transform:rotate(0deg);}
to { -webkit-transform:rotate(360deg);}
}
@-moz-keyframes rotate {
from {-moz-transform:rotate(0deg);}
to { -moz-transform:rotate(360deg);}
}
也许您可以将旋转动画应用于另一个包含背景的元素color/image?
.wrap {
overflow: hidden;
}
.to-rotate {
box-sizing: border-box;
padding: 2rem;
position: relative;
width: 60vh;
height: 60vh;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
}
.to-rotate::before {
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: url(https://i.ibb.co/PNkdKnR/bgexample.jpg) no-repeat center/cover;
-webkit-animation-name: rotate;
-webkit-animation-duration:6s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-moz-animation-name: rotate;
-moz-animation-duration:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-timing-function:linear;
border-radius: 100%;
}
img {
width: 100%;
max-width: 400px;
position: relative;
z-index: 2;
border: 10px solid white;
border-radius: 100%;
}
@-webkit-keyframes rotate {
from {-webkit-transform:rotate(0deg);}
to { -webkit-transform:rotate(360deg);}
}
@-moz-keyframes rotate {
from {-moz-transform:rotate(0deg);}
to { -moz-transform:rotate(360deg);}
}
<div class="wrap">
<div class="to-rotate">
<img src="https://i.ibb.co/b6Mc5VP/egg2.jpg" alt="egg" />
</div>
</div>
你好,我有一张带有背景图片的图片,我只需要为背景制作旋转动画,但动画适用于它们。
这是我的 css 代码:
.to-rotate .img{
-webkit-animation-name: rotate;
-webkit-animation-duration:6s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-moz-animation-name: rotate;
-moz-animation-duration:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-timing-function:linear;
}
@-webkit-keyframes rotate {
from {-webkit-transform:rotate(0deg);}
to { -webkit-transform:rotate(360deg);}
}
@-moz-keyframes rotate {
from {-moz-transform:rotate(0deg);}
to { -moz-transform:rotate(360deg);}
}
也许您可以将旋转动画应用于另一个包含背景的元素color/image?
.wrap {
overflow: hidden;
}
.to-rotate {
box-sizing: border-box;
padding: 2rem;
position: relative;
width: 60vh;
height: 60vh;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
}
.to-rotate::before {
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background: url(https://i.ibb.co/PNkdKnR/bgexample.jpg) no-repeat center/cover;
-webkit-animation-name: rotate;
-webkit-animation-duration:6s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-moz-animation-name: rotate;
-moz-animation-duration:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-timing-function:linear;
border-radius: 100%;
}
img {
width: 100%;
max-width: 400px;
position: relative;
z-index: 2;
border: 10px solid white;
border-radius: 100%;
}
@-webkit-keyframes rotate {
from {-webkit-transform:rotate(0deg);}
to { -webkit-transform:rotate(360deg);}
}
@-moz-keyframes rotate {
from {-moz-transform:rotate(0deg);}
to { -moz-transform:rotate(360deg);}
}
<div class="wrap">
<div class="to-rotate">
<img src="https://i.ibb.co/b6Mc5VP/egg2.jpg" alt="egg" />
</div>
</div>