我们可以使用general sibling selector (~
)来抵消其他卡,低于一个高度,这里130px
,这将给出预期的结果!
.example-box:hover ~ div.example-box {
margin-top: calc((35% * (var(--index))) + 130px);
}
完整css
.example-list {
width: 200px;
height: 100%;
display: block;
position: relative;
}
.example-box {
position: absolute;
height: 200px;
width: 200px;
padding: 20px 10px;
border: solid 1px #ccc;
box-sizing: border-box;
cursor: move;
background: white;
margin-top: calc(35% * (var(--index)));
}
.example-box:hover ~ div.example-box {
margin-top: calc((35% * (var(--index))) + 130px);
}
.cdk-drag-preview {
box-sizing: border-box;
border-radius: 4px;
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
}
.cdk-drag-placeholder {
opacity: 0;
}
.cdk-drag-animating {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
.example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
Stackblitz Demo