You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

翻转卡片正面Div滚轮滚动失效求助(滚动条可见但需点击)

解决翻转卡片正面滚轮无法滚动的问题

问题分析

正面卡片显示滚动条但无法通过滚轮滚动,核心原因是正面与背面元素重叠(均为绝对定位),未翻转状态下背面元素会拦截滚轮事件——尽管backface-visibility: hidden让背面不可见,但它依然存在于DOM层级中,会优先接收鼠标事件,导致正面无法响应滚轮操作。

解决方案

通过pointer-events属性控制不同状态下元素的事件接收权限:

  • 未翻转时,让背面元素不接收任何鼠标事件,确保事件穿透到正面
  • 翻转后,让正面元素不接收任何鼠标事件,确保事件穿透到背面

修改后的CSS代码

.cards {
    display: flex;
    flex-direction: row;
    padding: 0px;
}

.flip-card {
    background-color: transparent;
    perspective: 1000px;
    margin: 1em 1.4em 1em 0;
    cursor: pointer;
    position: relative;
    display: inline-block;
    width: 350px;
    height: 50vh;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

/* 翻转状态下,正面禁用事件,让背面接收操作 */
.flip-card.flipped .flip-card-front {
    pointer-events: none;
}

/* 未翻转状态下,背面禁用事件,让正面接收操作 */
.flip-card:not(.flipped) .flip-card-back {
    pointer-events: none;
}

.flip-card-inner {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.5s;
}

.flip-card-front {
    justify-content: flex-start;
    align-items: baseline;
}

.flip-card-back {
    transform: rotateY(180deg);
    justify-content: center;
    align-items: center;
}

.flip-card-front,
.flip-card-back {
    display: flex;
    position: absolute;
    backface-visibility: hidden;
    flex-wrap: wrap;
    width: 100%;
    height: 100%;
    padding: 15px;
    color: #222;
    background: whitesmoke;
    overflow-y: auto;
}

.flip-card:focus {
    box-shadow: 0 0 0 2px white, 0 0 0 4px #333;
}

补充说明

pointer-events: none会让元素完全不响应鼠标事件,事件会直接传递给下方的可见元素。配合状态选择器实现翻转前后的事件权限切换,就能确保当前显示的卡片面正常接收滚轮及其他鼠标操作。

内容的提问来源于stack exchange,提问作者learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 04:42:15