How to convert React-Draggable coordinates into Element.getBoundingClientRect()?

Đang mở
#694 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react
Lĩnh vực
frontend

Hướng nghiên cứu

Start by reviewing the Draggable component's onDrag data and the browser behavior of ref.getBoundingClientRect(). Reproduce the reported coordinate difference with the snippet, then document whether the values can be compared or converted and provide a minimal explanation of the coordinate systems involved.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I noticed that the x and y coordinates that React-Draggable gives out is completely different from what getBoundingClientRect gives out. Here's a snippet of my code:

const [position, setPosition] = useState({ x: 0, y: 0 });
const trackPos = (data) => {
     setPosition({ x: data.x, y: data.y });
};

<Draggable onDrag={(e, data) => trackPos(data)}>
     <div ref = {ref}>...</div>
</Draggable>

When I print out the values of both ref.getBoundingClientRect() from the component and that of data are completely different. Is there any way to convert these values?

Ngôn ngữ chính
JavaScript
Star
9.3k
Fork
1k
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
4

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react-grid-layout/react-draggable

Tất cả issue của react-grid-layout/react-draggable

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.