我希望能夠獲得圖像中點擊的位置。我想獲取圖像本身的坐標,而不是頁面容器中的坐標。我最接近的是這樣的:<template> <div class="image-annotation"> <div style="position: relative"> <!-- image-annotation__marker class has styles to center place the pointer in a absolute positioning --> <div class="image-annotation__marker" :style="markerStyle" /> <img ref="image" src="https://lh6.ggpht.com/HlgucZ0ylJAfZgusynnUwxNIgIp5htNhShF559x3dRXiuy_UdP3UQVLYW6c=s1200" alt="Art image" @click="onClickImage" /> </div> </div></template><script>import Vue from 'vue'import Component from 'vue-class-component'@Componentexport default class Counter extends Vue { public activeCoordinates: { x: number; y: number } | null = null; public $refs!: { image: HTMLElement } get hideSecondColumn() { return this.activeCoordinates !== null } get markerStyle() { if (this.activeCoordinates === null) return { display: 'none' } return { top: `${this.activeCoordinates.y}px`, left: `${this.activeCoordinates.x}px`, } } public onClickImage(event: MouseEvent) { this.activeCoordinates = { x: event.pageX - this.$refs.image.offsetTop, y: event.pageY - this.$refs.image.offsetLeft, } }}</script>但是當單擊圖像時,我在圖像中得到以下點(該點不完全是我單擊的位置)我想準確地了解我點擊圖片的位置
獲取點擊圖片的位置
慕后森
2023-04-01 15:58:59