如何在不旋转图像的情况下旋转剪辑路径?

Ars*_*tak 5 css css3 css-animations clip-path

我有一个CSS属性剪辑路径的图像.我添加了动画来旋转剪辑路径.我想只旋转剪辑路径,而不是图像.从下面的代码中,您可以了解我想要实现的目标.我这样做是为了让你知道我想要达到的目标.我的代码的问题是在每个关键帧上手动设置剪辑路径点需要花费大量时间.那么是否有任何简短的方法来实现以下代码结果而无需在关键帧上手动更改点数?我希望它很流畅,这很难通过手动设置点来设置.(请记住,我不需要那个使图像不可见的最后一个动画,我无法弄清楚它为什么会发生.

#profile-img {
    width: 15%;
    margin: 5%;
    -webkit-clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
    clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
    animation: clipRotateAnim 2s linear infinite;
}

@keyframes clipRotateAnim {
    0% {
        -webkit-clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
        clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
    }
    
    25% {
        -webkit-clip-path: polygon(100% 23%, 80% 0, 47% 34%, 16% 0, 0 19%, 26% 53%, 0 78%, 19% 100%, 51% 71%, 76% 100%, 100% 81%, 68% 51%);
        clip-path: polygon(100% 23%, 80% 0, 47% 34%, 16% 0, 0 19%, 26% 53%, 0 78%, 19% 100%, 51% 71%, 76% 100%, 100% 81%, 68% 51%);
    }
    50% {
        -webkit-clip-path: polygon(84% 100%, 100% 75%, 64% 56%, 100% 13%, 81% 0, 49% 28%, 22% 0, 0 29%, 28% 57%, 0 83%, 21% 100%, 42% 74%);
        clip-path: polygon(84% 100%, 100% 75%, 64% 56%, 100% 13%, 81% 0, 49% 28%, 22% 0, 0 29%, 28% 57%, 0 83%, 21% 100%, 42% 74%);
    }
    100% {
        -webkit-clip-path: polygon(27% 0, 0 19%, 29% 49%, 0 79%, 19% 100%, 45% 76%, 84% 100%, 100% 80%, 69% 56%, 100% 18%, 80% 0, 47% 33%);
        clip-path: polygon(27% 0, 0 19%, 29% 49%, 0 79%, 19% 100%, 45% 76%, 84% 100%, 100% 80%, 69% 56%, 100% 18%, 80% 0, 47% 33%);

    }
 
}
Run Code Online (Sandbox Code Playgroud)
<img id="profile-img" src="https://images.pexels.com/photos/1025804/pexels-photo-1025804.jpeg?auto=compress&cs=tinysrgb&h=350">
Run Code Online (Sandbox Code Playgroud)

Tem*_*fif 7

使用图像作为伪元素的背景并沿相反方向旋转它:

.image {
    width:200px;
    height:200px;
    margin: 20px;
    -webkit-clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
    clip-path: polygon(20% 0%, 0% 20%, 30% 50%, 0% 80%, 20% 100%, 50% 70%, 80% 100%, 100% 80%, 70% 50%, 100% 20%, 80% 0%, 50% 30%);
    animation: clipRotateAnim 2s linear infinite;
    position:relative;
    overflow:hidden;
}
.image:before {
  content:"";
  position:absolute;
  top:-10%;
  bottom:-10%;
  left:-10%;
  right:-10%;
  background:var(--i) center/cover;
  animation: clipRotateAnim 2s linear infinite reverse;
}
@keyframes clipRotateAnim{
  from{transform:rotate(0)}
  to{transform:rotate(360deg)}
}
Run Code Online (Sandbox Code Playgroud)
<div class="image"  style="--i:url(https://images.pexels.com/photos/1025804/pexels-photo-1025804.jpeg?auto=compress&cs=tinysrgb&h=350)">
</div>
Run Code Online (Sandbox Code Playgroud)

要避免的另一个想法clip-path是使用背景在您旋转的图像上方创建另一个图层.在这种情况下,您将没有透明度,但您将获得更好的浏览器支持.

.image {
    width:200px;
    height:200px;
    margin: 20px;
    position:relative;
   background:var(--i) center/cover;
   overflow:hidden;
}
.image:before {
  content:"";
  position:absolute;
  top:0;
  bottom:0;
  left:0;
  right:0;
  box-shadow:0 0 200px 200px #fff;
  background-image:
    linear-gradient(#fff,#fff),linear-gradient(#fff,#fff),linear-gradient(#fff,#fff),linear-gradient(#fff,#fff);
  background-size:calc(50% - 30px) calc(50% - 30px);
  background-position:top left,top right,bottom left,bottom right;
  background-repeat:no-repeat;
  animation: clipRotateAnim 2s linear infinite;
}
@keyframes clipRotateAnim{
  from{transform:rotate(0)}
  to{transform:rotate(360deg)}
}
Run Code Online (Sandbox Code Playgroud)
<div class="image"  style="--i:url(https://images.pexels.com/photos/1025804/pexels-photo-1025804.jpeg?auto=compress&cs=tinysrgb&h=350)">
  
</div>
Run Code Online (Sandbox Code Playgroud)