Skip to content

Commit 78494de

Browse files
committed
fix: scroll to element when not in view
1 parent 350573d commit 78494de

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/components/toolbar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<script>
2222
import widget from '../plugins/widget'
2323
import { move } from '../mixins'
24-
import { cumulativeOffset } from '../utils/offset'
24+
import { cumulativeOffset, checkInView } from '../utils/offset'
2525
2626
export default {
2727
mixins: [move],
@@ -58,7 +58,7 @@ export default {
5858
})
5959
let viewport = document.querySelector('#viewport')
6060
let target = viewport.querySelector(`[data-uuid='${item.uuid}']`)
61-
if (target) {
61+
if (target && !checkInView(target)) {
6262
viewport.scrollTop = (cumulativeOffset(target).top - 50) * this.zoom / 100
6363
}
6464
}

src/utils/offset.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ export function cumulativeOffset (element) {
1313
left: left
1414
}
1515
}
16+
17+
export function checkInView (el) {
18+
let rect = el.getBoundingClientRect()
19+
return (
20+
rect.top < window.innerHeight &&
21+
(rect.left < window.innerWidth &&
22+
rect.right > 0)
23+
)
24+
}

0 commit comments

Comments
 (0)