如果我从5个不同的部分构建图像(用于创建效果),一个简单的方法是使用相同的样式创建5个不同的类(我正在使用反应) . 我想要实现的效果是在悬停时旋转图像的5个部分 . 这是jsx:

var sectionStyle = {
            width: '100%',
            height: '100%',
            backfaceVisibility: 'hidden',
            backgroundImage: 'url(' + background + ')',
            backgroundSize: 'cover',
          };
    return(
       <div className="container1">
       <div className="thumb-details"></div>
       <div className="part p01">
           <figure className="f1" style={sectionStyle}/>
           <div className="f2"></div>
       </div>
       <div className="part p02">
           <figure className="f1" style={sectionStyle}/>
           <div className="f2"></div>
       </div>
       <div className="part p03">
           <figure className="f1" style={sectionStyle}/>
           <div className="f2"></div>
       </div>
       <div className="part p04">
           <figure className="f1" style={sectionStyle}/>
           <div className="f2"></div>
       </div>
       <div className="part p05">
           <figure className="f1" style={sectionStyle}/>
           <div className="f2"></div>
       </div>
   </div>

然后我可以手动计算每个图形类的背景位置,以便每个图形图像将从上一个结束的位置开始:

.thumbnail {
 width: 100%;
 height: 20vw;
}

.container1 {
  width: 20vw;
  height: 20vw;
  position: absolute;
  /* background-color: blue; */
}

.thumb-details {
  max-width: 100%;
  height: 20vw;
  background-color: yellow;
  position: absolute;
  left:0;
  right:0;
  transition: opacity .2s ease-out;
}

.part {
  width: 20%;
  height: 100%;
  position: absolute;
  transform: rotateY(0deg);
  transform-style:preserve-3d;
  transition: all .5s ease-out;
}

.f1 {
  transform: rotateY(0deg);
}

.p01 {
  left: 0;
}

.p01 figure {
  background-position: 0px 0px;
}

.p02 {
  left: 20%;
}

.p02 figure {
  background-position: -4vw 0px;
}

.p03 {
  left: 40%;
}

.p03 figure {
  background-position: -8vw 0px;
}

.p04 {
  left: 60%;
}

.p04 figure {
  background-position: -12vw 0px;
}

.p05 {
  left: 80%;
}

.p05 figure {
  background-position: -16vw 0px;
}

.container1:hover .part {
  transform: rotateY(180deg);
}

它只是20vw除以5,然后我设置每个的背景位置(从第二个开始)到前一个结束的开始 .

这工作正常 . 问题是 - 图像不居中,我不能设置它的总宽度和高度,因为如果我使用“background-position:center”,就像我想的那样,那么我就不能再跟踪图像的每个部分了 .

我希望听起来并不复杂 . 我理论上需要的是计算图像的不同偏移(我在CSS中显示的5个不同的偏移),但是在它被定位为居中之后从图像计算它 . 这很重要,因为我希望图像具有响应性 .

可能吗?

提前致谢