Skip to content

Commit

Permalink
update drag card
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Feb 27, 2022
1 parent 3685374 commit 70da7ae
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/components/StickyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const StickyCard: React.FC<Props> = (props) => {
}, []);

const handleStickyCardMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => {
const cardEl = event.currentTarget;
const shiftX = event.clientX - cardEl.getBoundingClientRect().left;
const shiftY = event.clientY - cardEl.getBoundingClientRect().top;
const { left, top } = event.currentTarget.getBoundingClientRect();
const shiftX = event.clientX - left;
const shiftY = event.clientY - top;

const handleMouseMove = (event: MouseEvent) => {
dispatch(
Expand All @@ -41,20 +41,11 @@ const StickyCard: React.FC<Props> = (props) => {
);
};

cardEl.addEventListener("mousemove", handleMouseMove);
cardEl.addEventListener(
document.addEventListener("mousemove", handleMouseMove);
document.addEventListener(
"mouseup",
() => {
cardEl.removeEventListener("mousemove", handleMouseMove);
},
{
once: true,
}
);
cardEl.addEventListener(
"mouseleave",
() => {
cardEl.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mousemove", handleMouseMove);
},
{
once: true,
Expand Down

0 comments on commit 70da7ae

Please sign in to comment.