应用translate3d 时插入符号/文本光标停止
也许这是一个错误,但对我来说,它在 Safari 和 Chrome 中都会发生,这很奇怪:
当您将 CSS -webkit-transform:translate3D(10px, 10px, 0)
应用于输入或任何内部有输入的元素时,插入符号光标不再闪烁也无法用键盘控制? (事实上,使用键盘时选择本身会改变位置,但插入符号不会更新其位置)
是否有任何解决方法?
Perhaps this is a bug, but it is weird it happens both in Safari and Chrome for me:
When you apply CSS -webkit-transform: translate3D(10px, 10px, 0)
to an input or any element that has an input inside, the caret cursor won't blink anymore neither can be controlled with the keyboard? (In fact the selection itself changes place when using the keyboard but the caret doesn't update its position)
Is there any workaround for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一件烦人的事情。按下按键时更新 CSS 属性之一会强制它重新绘制输入,但这并不理想,因为它依赖于 JavaScript。我在输入的按键上切换了一个不可见的文本阴影,它允许您使用箭头键移动插入符号,但不能修复不闪烁的插入符号。
http://jsfiddle.net/4bqkP/3/
编辑:添加脚本的
form
元素。This is an annoying one. Updating one of the css properties on key down forces it to redraw the input, but it's not ideal as it relies on javascript. I toggle an invisible text shadow on keydown on the input, that lets you use the arrow keys to move the caret but doesn't fix the non-blinking caret.
http://jsfiddle.net/4bqkP/3/
edit: added the
form
element to the script.根据 Jedidiah 的回答,我通过使用 requestAnimationFrame 不断切换输入字段的类名(无论键盘活动如何)来改进解决方案。
http://jsfiddle.net/wBpNq/3/
这看起来暂时解决了这个问题,包括使光标再次闪烁,尽管当/如果您开始键入时光标会停止闪烁。
Based on Jedidiah's answer, I've improved the solution by using requestAnimationFrame to constantly toggle the classname of the input field regardless of keyboard activity.
http://jsfiddle.net/wBpNq/3/
This looks to fix the issue for now, including making the cursor blink again, although when/if you start typing the cursor stops blinking.