typescript
1<template> 2 <div id="lineSvgPractice" class="lineSvgPractice" @mousemove="resize" @mouseup="mouseup" > 3 4 5 6 <div class="area"> 7 <svg class="svg" width="100" height="100" viewBox="0 0 100 100" > 8 <circle :cx="point1XNow" :cy="point1YNow" r="1.4" fill="#ffffff" stroke="#000" @mousedown="point1Active"></circle> 9 <line :x1="line1XNow" :y1="line1YNow" :x2="line2XNow" :y2="line2YNow" stroke="#000"></line> 10 <circle :cx="point2XNow" :cy="point2YNow" r="1.4" fill="#ffffff" stroke="#000" @mousedown="point2Active"></circle> 11 </svg> 12 </div> 13 14 15 16 </div> 17</template> 18 19<script lang="ts"> 20import { Component, Prop, Vue } from "vue-property-decorator"; 21 22@Component({ 23 components: { 24 } 25}) 26export default class LineSvgPractice extends Vue { 27 28 29 30/*--------------------------------------------------*/ 31 32 point1ActiveFlag = false 33 point1XBefore = 29 34 point1YBefore = 29 35 point1XNow = 29 36 point1YNow = 29 37 38 line1XBefore = 30 39 line1YBefore = 30 40 line1XNow = 30 41 line1YNow = 30 42 43/*--------------------------------------------------*/ 44 45 point2ActiveFlag = false 46 point2XBefore = 59 47 point2YBefore = 59 48 point2XNow = 59 49 point2YNow = 59 50 51 line2XBefore = 60 52 line2YBefore = 60 53 line2XNow = 60 54 line2YNow = 60 55 56/*--------------------------------------------------*/ 57 58 pointStartX = 0 59 pointStartY = 0 60 61 public point1Active(event){ 62 console.log(event) 63 this.point1ActiveFlag = true 64 this.pointStartX = event.clientX 65 this.pointStartY = event.clientY 66 } 67 68 public point2Active(event){ 69 this.point2ActiveFlag = true 70 this.pointStartX = event.clientX 71 this.pointStartY = event.clientY 72 } 73 74 public mouseup(){ 75 this.point1ActiveFlag = false 76 this.point2ActiveFlag = false 77 this.point1XBefore = this.point1XNow 78 this.point1YBefore = this.point1YNow 79 this.line1XBefore = this.line1XNow 80 this.line1YBefore = this.line1YNow 81 this.point2XBefore = this.point2XNow 82 this.point2YBefore = this.point2YNow 83 this.line2XBefore = this.line2XNow 84 this.line2YBefore = this.line2YNow 85 } 86 87 public resize(event){ 88 if(this.point1ActiveFlag){ 89 this.point1XNow = this.point1XBefore + (event.clientX - this.pointStartX) 90 this.point1YNow = this.point1YBefore + (event.clientY - this.pointStartY) 91 this.line1XNow = this.line1XBefore + (event.clientX - this.pointStartX) 92 this.line1YNow = this.line1YBefore + (event.clientY - this.pointStartY) 93 } 94 95 if(this.point2ActiveFlag){ 96 this.point2XNow = this.point2XBefore + (event.clientX - this.pointStartX) 97 this.point2YNow = this.point2YBefore + (event.clientY - this.pointStartY) 98 this.line2XNow = this.line2XBefore + (event.clientX - this.pointStartX) 99 this.line2YNow = this.line2YBefore + (event.clientY - this.pointStartY) 100 } 101 } 102 103 104} 105</script> 106 107<style lang="scss"> 108.lineSvgPractice { 109 110 .area{ 111 position: relative; 112 width: 100vw; 113 height: 80vh; 114 .svg{ 115 position: absolute; 116 top: 0px; 117 width: 100%; 118 height: 100%; 119 circle{ 120 cursor : pointer 121 } 122 } 123 } 124 125} 126</style>
線の両端をドラッグして移動できる、コードを書いたのですが、マウスの移動距離とsvg要素の移動距離が合いません...
少しドラッグしただけで、すごい動いてしまいます...
解決策をお伺いしたいです...
そもそもこのやり方は正しいのでしょうか
なんか下手な気がして
開発環境は、vue-cli3.0です↓
https://alligator.io/vuejs/using-new-vue-cli-3/
yhg様、恐縮ですが回答依頼させていただきました...
良かったら教えてください!(>_<)

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/30 02:08
退会済みユーザー
2018/07/30 04:58 編集
2018/07/30 06:42
退会済みユーザー
2018/07/31 08:18
2018/10/24 07:31