javascript - 从 onFocus 事件中检索 TextInput 的屏幕坐标
问题描述
我需要从 onFocus 事件中检索 TextInput 在屏幕上的位置。我还没有找到有关此的文档,我的问题是我无法从焦点触发的事件中找出元素。这里的代码:
_handleOnFocus(event) {
console(event.nativeEvent.target.layout.y); // where is the y coordinate?
}
回调插入此处:
<TextInput onFocus={
onFocus={event => {this._handleOnFocus(event);}}} ... />
解决方案
您可以通过event.target.offsetTop
但考虑到它会从最近的非静态父级返回偏移量来访问它。如果需要绝对偏移量,请参考这个问题:Finding element's position relative to the document
推荐阅读
- javascript - 鼠标移出后显示子菜单
- exceldatareader - ExcelDataReader 3.4 - System.IO.FileLoadException
- java - 如果一个java pojo被声明为一个对象,如何根据运行时类型控制jackson序列化?
- vb.net - 如何找到二进制 16 位数字的每个组合
- c# - 如何获取 Windows 客户端用户 ASPX C#
- python - 从 dict1 更新 dict2 的值,但在 dict2 的特定位置
- java - 使用 S/4HANA Cloud SDK >= 2.0.0 执行 OData 查询时的 DestinationAccessException
- dialog - wxPython;如果取消一个对话框,则关闭所有对话框
- c# - MONO - C# UdpClient 未接收来自本地广播 ip 的消息
- python - Matplotlib 对数轴刻度