JavaScript落叶动画页面输入文本框无法编辑问题排查请求
问题:输入框无法输入(被落叶动画层遮挡)
原因分析
.leaf-scene采用绝对定位,默认会覆盖在同级的form元素上方,抢占了鼠标焦点和输入事件,导致输入框无法被选中并输入内容。
解决方案
两种方案任选其一即可:
方案1:提升输入框容器的层级
给form添加相对定位和足够高的z-index,让它显示在动画层上方:
form { width: 600px; margin: 0px auto; padding: 15px; position: relative; /* 需设置定位才能生效z-index */ z-index: 10; /* 数值大于动画层默认层级即可 */ }
方案2:让动画层不接收鼠标事件
给.leaf-scene设置pointer-events: none,使鼠标事件直接穿透到下方的输入框:
.leaf-scene { position: absolute; top: 0; left: 0; bottom: 0; width: 100%; transform-style: preserve-3d; pointer-events: none; /* 禁止该层响应鼠标事件 */ }
修改后的完整CSS示例(以方案1为例)
body, html { height: 100%; } form { width: 600px; margin: 0px auto; padding: 15px; position: relative; z-index: 10; } input[type=text] { display: block; padding: 10px; box-sizing: border-box; font-size: x-large; margin-top: 25%; } input[type=text] { width: 100%; margin-bottom: 15px; } .falling-leaves { position: absolute; top: 0; bottom: 0; left: 50%; width: 100%; max-width: 880px; max-height: 880px; transform: translate(-50%, 0); border: 20px solid #fff; border-radius: 50px; background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/125707/sidebar-bg.png) no-repeat center center; background-size: cover; overflow: hidden; } .leaf-scene { position: absolute; top: 0; left: 0; bottom: 0; width: 100%; transform-style: preserve-3d; } .leaf-scene div { position: absolute; top: 0; left: 0; width: 20px; height: 20px; background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/125707/leaf.svg) no-repeat; background-size: 100%; transform-style: preserve-3d; backface-visibility: visible; }
内容的提问来源于stack exchange,提问作者suchit
相关产品推荐
相关产品推荐

