diff --git a/src/GGanttBar.vue b/src/GGanttBar.vue
index 3c7c74f..49dd4ef 100644
--- a/src/GGanttBar.vue
+++ b/src/GGanttBar.vue
@@ -273,7 +273,8 @@ export default {
},
drag(e) {
- const chart = document.querySelector('#g-gantt-chart')
+ const chart = e.target.closest('.g-gantt-chart')
+ if (!chart) return
let barWidth = this.$refs['g-gantt-bar'].getBoundingClientRect().width
let newXStart =
chart.scrollLeft +
@@ -291,7 +292,9 @@ export default {
},
dragByHandleLeft(e) {
- let newXStart = e.clientX - this.barContainer.left
+ const chart = e.target.closest('.g-gantt-chart')
+ if (!chart) return
+ let newXStart = chart.scrollLeft + e.clientX - this.barContainer.left
let newStartMoment = this.mapPositionToTime(newXStart)
if (
this.barEndMoment.diff(newStartMoment, this.timeUnit) < 1 ||
@@ -304,7 +307,9 @@ export default {
},
dragByHandleRight(e) {
- let newXEnd = e.clientX - this.barContainer.left
+ const chart = e.target.closest('.g-gantt-chart')
+ if (!chart) return
+ let newXEnd = chart.scrollLeft + e.clientX - this.barContainer.left
let newEndMoment = this.mapPositionToTime(newXEnd)
if (
newEndMoment.isSameOrBefore(this.barStartMoment, this.timeUnit) ||
diff --git a/src/GGanttChart.vue b/src/GGanttChart.vue
index 7ea7d1c..de5937c 100644
--- a/src/GGanttChart.vue
+++ b/src/GGanttChart.vue
@@ -1,6 +1,6 @@
@@ -83,7 +84,7 @@ export default {
},
mounted() {
- this.timemarker = document.querySelector('#g-timeaxis-marker')
+ this.timemarker = this.$refs['g-timeaxis-marker']
this.initAxis()
this.onWindowResize()
window.addEventListener('resize', this.onWindowResize)
@@ -175,7 +176,9 @@ export default {
},
moveTimemarker(event) {
+ const chart = this.timemarker.closest('.g-gantt-chart')
this.timemarker.style.left =
+ chart.scrollLeft +
event.clientX -
this.timemarkerOffset -
this.horizontalAxisContainer.left +
@@ -183,9 +186,8 @@ export default {
},
onWindowResize() {
- this.horizontalAxisContainer = document
- .querySelector('#g-timeaxis')
- .getBoundingClientRect()
+ this.horizontalAxisContainer =
+ this.$refs['g-timeaxis'].getBoundingClientRect()
this.hourFontSize =
Math.min(
9.5,
@@ -228,7 +230,7 @@ export default {