Skip to content

Commit

Permalink
fix: 修改滚动到节点的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
gene9831 committed Apr 16, 2024
1 parent 681a6fa commit a34fe05
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/canvas/src/components/container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,19 @@ export const scrollToNode = (element) => {
if (element) {
const container = getDocument().documentElement
const { clientWidth, clientHeight } = container
const { x, y, width, height } = element.getBoundingClientRect()
const { left, right, top, bottom } = element.getBoundingClientRect()
const option = {}

if (x < 0) {
option.left = container.scrollLeft + x - SCROLL_MARGIN
} else if (x > clientWidth) {
option.left = x + width - clientWidth + SCROLL_MARGIN
if (right < 0) {
option.left = container.scrollLeft + left - SCROLL_MARGIN
} else if (left > clientWidth) {
option.left = right - clientWidth + SCROLL_MARGIN
}

if (y < 0) {
option.top = container.scrollTop + y - SCROLL_MARGIN
} else if (y > clientHeight) {
option.top = y + height - clientHeight + SCROLL_MARGIN
if (bottom < 0) {
option.top = container.scrollTop + top - SCROLL_MARGIN
} else if (top > clientHeight) {
option.top = bottom - clientHeight + SCROLL_MARGIN
}

if (typeof option.left === 'number' || typeof option.top === 'number') {
Expand Down

0 comments on commit a34fe05

Please sign in to comment.