首页 > 解决方案 > 如何修复剪切路径切断包裹图像的一小部分?

问题描述

我正在尝试正确显示带有剪辑路径的容器内的图像。我还想在悬停时添加轻微的缩放效果。

不悬停时底部的一小部分被切断。但是,一旦您将图像悬停并放大,一切看起来都很好。

我无法设置固定高度,这样可以更轻松地解决问题,因为我想稍后将图像添加到响应式弹性容器中。

我在这个 jsfiddle 中将问题简化为核心:https ://jsfiddle.net/pzf459cd/1/

.Image-Wrapper {
  width: 50%;
}

.Image-Zoom-Wrapper {
  clip-path: polygon(100% 0, 100% 91%, 62% 100%, 0 91%, 0 0, 62% 9%);
  object-fit: contain;
}

.Image {
  transition: all 0.5s linear;
}

.Image-Wrapper:hover .Image {
  transform: scale(1.05, 1.05);
  transition: all 0.5s linear;
}

body {
  background-color: #000;
}
<div class="Image-Wrapper">
  <div class="Image-Zoom-Wrapper">
    <img class="Image" src="https://picsum.photos/id/304/500/300">
  </div>
</div>

标签: htmlcsscss-animationsclip-path

解决方案


请参阅下面的类似任务的解决方案。它有效,但可能有一个更容易/更好的。

jsfiddle:https ://jsfiddle.net/fj5z7bue/

.wrap{
  position: relative;
  width: 50%;
  filter: drop-shadow(3px 4px 8px rgba(38, 50, 56, 0.4));
}
.clip{
  position: relative;
  display: block;
  overflow: hidden;
  clip-path: polygon(60% 5%, 100% 0, 100% 95%, 60% 100%, 0 95%, 0 0);
  height: 100%;
  width: 100%;
  background-color: rgb(240, 240, 240);
}
.pseudoimg{
  width: 100%;
  opacity: 0;
}
.img{
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  background-image: url('https://picsum.photos/id/304/500/300');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  min-height: 100%;
  min-width: 100%;
  transform: scale(1);
  transition: all 0.4s ease-out;
}
.wrap:hover{
  cursor: pointer;
}
.wrap:hover .img{
  transform: scale(1.4);
  transition: all 12s ease-out;
}
.button{
  position: absolute;
  height: 60px;
  width: 60px;
  border-radius: 30px;
  background-color: rgb(255, 255, 255);
  z-index: 3;
  right: -15px;
  bottom: -5px;
  filter: drop-shadow(3px 4px 8px rgba(38, 50, 56, 0.4));
}
<div class="wrap">
	<div class="button"></div>
	<div class="clip">
		<img class="pseudoimg" src="https://picsum.photos/id/304/500/300"/>
		<div class="img"></div>
	</div>
</div>


推荐阅读