JavaScriptを色々あれこれしようとするがひたすら失敗を繰り返している
| Revision | 16 (tree) |
|---|---|
| Time | 2016-11-15 08:19:19 |
| Author | |
textboxサイズ変更方法変更中
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | this.DOMobject = null; |
| 16 | 16 | this.renderFunc = new Queue(); |
| 17 | 17 | |
| 18 | + this.originalWidth = 0; | |
| 19 | + this.originalHeight = 0; | |
| 20 | + | |
| 18 | 21 | this.dropinitsize = 100.0; |
| 19 | 22 | } |
| 20 | 23 |
| @@ -60,11 +63,16 @@ | ||
| 60 | 63 | this.y = rect.top; |
| 61 | 64 | this.width = rect.right - rect.left; |
| 62 | 65 | this.height = rect.bottom - rect.top; |
| 66 | + this.originalWidth = this.width; | |
| 67 | + this.originalHeight = this.height; | |
| 63 | 68 | |
| 64 | 69 | // 画面に影響しない範囲で作成できるところまで Dom objectを作成する |
| 65 | 70 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 66 | 71 | this.DOMobject = document.createElement(elType); |
| 67 | 72 | this.DOMobject.dataset.objid = this.ObjID; |
| 73 | + this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ | |
| 74 | + this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 75 | + this.DOMobject.dataset.degree = 0; | |
| 68 | 76 | this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 69 | 77 | if (null != type.match(/imagebox/)) { |
| 70 | 78 | // imageの場合、画像読み込み完了後に描画する必要がある |
| @@ -100,10 +108,14 @@ | ||
| 100 | 108 | this.DOMobject.src = evt.target.result; |
| 101 | 109 | this.DOMobject.onload = function (evt) { |
| 102 | 110 | // 画像としての読み込み完了後に幅と高さが取れる |
| 103 | - // | |
| 111 | + // 大きすぎ/小さすぎても困るため初期サイズに収まるように拡大/縮小 | |
| 104 | 112 | let rect = this.calcImageWH(parseInt(evt.target.naturalWidth), parseInt(evt.target.naturalHeight)); |
| 105 | 113 | this.width = rect.right - rect.left; |
| 106 | 114 | this.height = rect.bottom - rect.top; |
| 115 | + this.originalWidth = this.width; | |
| 116 | + this.originalHeight = this.height; | |
| 117 | + this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ | |
| 118 | + this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 107 | 119 | // 表示サイズ取得完了したので画面に表示 |
| 108 | 120 | this.renderFunc.enqueue(this.renderCreate.bind(this)); |
| 109 | 121 | }.bind(this); |
| @@ -182,6 +194,7 @@ | ||
| 182 | 194 | |
| 183 | 195 | rollbox(degree) { |
| 184 | 196 | this.degree = degree; |
| 197 | + this.DOMobject.dataset.degree = degree; | |
| 185 | 198 | this.renderFunc.enqueue(this.renderrollbox.bind(this)); |
| 186 | 199 | } |
| 187 | 200 | renderrollbox() { |
| @@ -228,6 +241,7 @@ | ||
| 228 | 241 | // dispObjがあった位置からマウス移動分移動させた後の位置取得 |
| 229 | 242 | moveX = this.x + moveX; |
| 230 | 243 | moveY = this.y + moveY; |
| 244 | + | |
| 231 | 245 | this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); |
| 232 | 246 | } |
| 233 | 247 | renderMoveDragging(x, y) { |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | let originX = parseInt(this.clingingPartner.style.width) / 2; |
| 42 | 42 | let originY = parseInt(this.clingingPartner.style.height) / 2; |
| 43 | - | |
| 43 | + // DOM 描画先rect 回転の中心位置 | |
| 44 | 44 | this.renderClingingSetPosition(this.DOM[0], this.getRectLeft(), (originX + this.lineWidth / 2) + 'px', '50%'); |
| 45 | 45 | this.renderClingingSetPosition(this.DOM[1], this.getRectTop(), '50%', (originY + this.lineWidth / 2) + 'px'); |
| 46 | 46 | this.renderClingingSetPosition(this.DOM[2], this.getRectRight(), (originX - this.lineWidth / 2) * -1 + 'px', '50%'); |
| @@ -268,12 +268,49 @@ | ||
| 268 | 268 | // 移動量取得 |
| 269 | 269 | let moveX = this.endDragX - this.startDragX; |
| 270 | 270 | let moveY = this.endDragY - this.startDragY; |
| 271 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 271 | + | |
| 272 | + switch(2){ | |
| 273 | + case 0: | |
| 274 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 275 | + break; | |
| 276 | + case 1: | |
| 277 | + { | |
| 278 | + let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 279 | + let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 280 | + let scaleX = (orgwidth + moveX) / orgwidth; | |
| 281 | + let scaleY = (orgheight + moveY) / orgheight; | |
| 282 | + | |
| 283 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, scaleX, scaleY)); | |
| 284 | + } | |
| 285 | + break; | |
| 286 | + case 2: | |
| 287 | + { | |
| 288 | + let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 289 | + let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 290 | + let scaleX = (this.scaleStartWidth + moveX) / orgwidth; | |
| 291 | + let scaleY = (this.scaleStartHeight + moveY) / orgheight; | |
| 292 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleX, scaleY)); | |
| 293 | + } | |
| 294 | + break; | |
| 295 | + } | |
| 272 | 296 | } |
| 273 | - renderMouseMoveScale(width, height) { | |
| 274 | - this.clingingPartner.style.width = width + "px"; | |
| 275 | - this.clingingPartner.style.height = height + "px"; | |
| 297 | + renderMouseMoveScale(width, height, scalex, scaley) { | |
| 276 | 298 | this.clingingPartner.style.opacity = 0.4; |
| 299 | + | |
| 300 | + switch(2){ | |
| 301 | + case 0: | |
| 302 | + this.clingingPartner.style.width = width + "px"; | |
| 303 | + this.clingingPartner.style.height = height + "px"; | |
| 304 | + break; | |
| 305 | + case 1: | |
| 306 | + this.clingingPartner.style.transform = 'scaleX(' + width + ') scaleY(' + height + ') rotateZ(' + parseInt(this.clingingPartner.dataset.degree) + 'deg);'; | |
| 307 | + break; | |
| 308 | + case 2: | |
| 309 | + this.clingingPartner.style.width = width + "px"; | |
| 310 | + this.clingingPartner.style.height = height + "px"; | |
| 311 | + this.clingingPartner.style.fontSize = (scaley * 100) + '%'; | |
| 312 | + break; | |
| 313 | + } | |
| 277 | 314 | } |
| 278 | 315 | mouseUpScale(evt) { |
| 279 | 316 | this.debuglog('mouseUpScale'); |
| @@ -15,6 +15,9 @@ | ||
| 15 | 15 | this.DOMobject = null; |
| 16 | 16 | this.renderFunc = new Queue(); |
| 17 | 17 | |
| 18 | + this.originalWidth = 0; | |
| 19 | + this.originalHeight = 0; | |
| 20 | + | |
| 18 | 21 | this.dropinitsize = 100.0; |
| 19 | 22 | } |
| 20 | 23 |
| @@ -60,11 +63,16 @@ | ||
| 60 | 63 | this.y = rect.top; |
| 61 | 64 | this.width = rect.right - rect.left; |
| 62 | 65 | this.height = rect.bottom - rect.top; |
| 66 | + this.originalWidth = this.width; | |
| 67 | + this.originalHeight = this.height; | |
| 63 | 68 | |
| 64 | 69 | // 画面に影響しない範囲で作成できるところまで Dom objectを作成する |
| 65 | 70 | let elType = (null != type.match(/imagebox/)) ? 'img' : 'div'; |
| 66 | 71 | this.DOMobject = document.createElement(elType); |
| 67 | 72 | this.DOMobject.dataset.objid = this.ObjID; |
| 73 | + this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ | |
| 74 | + this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 75 | + this.DOMobject.dataset.degree = 0; | |
| 68 | 76 | this.DOMobject.addEventListener('mousedown', this.onMouseDown.bind(this), false); |
| 69 | 77 | if (null != type.match(/imagebox/)) { |
| 70 | 78 | // imageの場合、画像読み込み完了後に描画する必要がある |
| @@ -100,10 +108,14 @@ | ||
| 100 | 108 | this.DOMobject.src = evt.target.result; |
| 101 | 109 | this.DOMobject.onload = function (evt) { |
| 102 | 110 | // 画像としての読み込み完了後に幅と高さが取れる |
| 103 | - // | |
| 111 | + // 大きすぎ/小さすぎても困るため初期サイズに収まるように拡大/縮小 | |
| 104 | 112 | let rect = this.calcImageWH(parseInt(evt.target.naturalWidth), parseInt(evt.target.naturalHeight)); |
| 105 | 113 | this.width = rect.right - rect.left; |
| 106 | 114 | this.height = rect.bottom - rect.top; |
| 115 | + this.originalWidth = this.width; | |
| 116 | + this.originalHeight = this.height; | |
| 117 | + this.DOMobject.dataset.orgwidth = this.originalWidth; // transform: scaleの基準サイズ | |
| 118 | + this.DOMobject.dataset.orgheight = this.originalHeight; | |
| 107 | 119 | // 表示サイズ取得完了したので画面に表示 |
| 108 | 120 | this.renderFunc.enqueue(this.renderCreate.bind(this)); |
| 109 | 121 | }.bind(this); |
| @@ -182,6 +194,7 @@ | ||
| 182 | 194 | |
| 183 | 195 | rollbox(degree) { |
| 184 | 196 | this.degree = degree; |
| 197 | + this.DOMobject.dataset.degree = degree; | |
| 185 | 198 | this.renderFunc.enqueue(this.renderrollbox.bind(this)); |
| 186 | 199 | } |
| 187 | 200 | renderrollbox() { |
| @@ -228,6 +241,7 @@ | ||
| 228 | 241 | // dispObjがあった位置からマウス移動分移動させた後の位置取得 |
| 229 | 242 | moveX = this.x + moveX; |
| 230 | 243 | moveY = this.y + moveY; |
| 244 | + | |
| 231 | 245 | this.renderFunc.enqueue(this.renderMoveDragging.bind(this, moveX, moveY)); |
| 232 | 246 | } |
| 233 | 247 | renderMoveDragging(x, y) { |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | let originX = parseInt(this.clingingPartner.style.width) / 2; |
| 42 | 42 | let originY = parseInt(this.clingingPartner.style.height) / 2; |
| 43 | - | |
| 43 | + // DOM 描画先rect 回転の中心位置 | |
| 44 | 44 | this.renderClingingSetPosition(this.DOM[0], this.getRectLeft(), (originX + this.lineWidth / 2) + 'px', '50%'); |
| 45 | 45 | this.renderClingingSetPosition(this.DOM[1], this.getRectTop(), '50%', (originY + this.lineWidth / 2) + 'px'); |
| 46 | 46 | this.renderClingingSetPosition(this.DOM[2], this.getRectRight(), (originX - this.lineWidth / 2) * -1 + 'px', '50%'); |
| @@ -268,12 +268,49 @@ | ||
| 268 | 268 | // 移動量取得 |
| 269 | 269 | let moveX = this.endDragX - this.startDragX; |
| 270 | 270 | let moveY = this.endDragY - this.startDragY; |
| 271 | - this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 271 | + | |
| 272 | + switch(2){ | |
| 273 | + case 0: | |
| 274 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY)); | |
| 275 | + break; | |
| 276 | + case 1: | |
| 277 | + { | |
| 278 | + let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 279 | + let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 280 | + let scaleX = (orgwidth + moveX) / orgwidth; | |
| 281 | + let scaleY = (orgheight + moveY) / orgheight; | |
| 282 | + | |
| 283 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, scaleX, scaleY)); | |
| 284 | + } | |
| 285 | + break; | |
| 286 | + case 2: | |
| 287 | + { | |
| 288 | + let orgwidth = parseInt(this.clingingPartner.dataset.orgwidth); | |
| 289 | + let orgheight = parseInt(this.clingingPartner.dataset.orgheight); | |
| 290 | + let scaleX = (this.scaleStartWidth + moveX) / orgwidth; | |
| 291 | + let scaleY = (this.scaleStartHeight + moveY) / orgheight; | |
| 292 | + this.renderFunc.enqueue(this.renderMouseMoveScale.bind(this, this.scaleStartWidth + moveX, this.scaleStartHeight + moveY, scaleX, scaleY)); | |
| 293 | + } | |
| 294 | + break; | |
| 295 | + } | |
| 272 | 296 | } |
| 273 | - renderMouseMoveScale(width, height) { | |
| 274 | - this.clingingPartner.style.width = width + "px"; | |
| 275 | - this.clingingPartner.style.height = height + "px"; | |
| 297 | + renderMouseMoveScale(width, height, scalex, scaley) { | |
| 276 | 298 | this.clingingPartner.style.opacity = 0.4; |
| 299 | + | |
| 300 | + switch(2){ | |
| 301 | + case 0: | |
| 302 | + this.clingingPartner.style.width = width + "px"; | |
| 303 | + this.clingingPartner.style.height = height + "px"; | |
| 304 | + break; | |
| 305 | + case 1: | |
| 306 | + this.clingingPartner.style.transform = 'scaleX(' + width + ') scaleY(' + height + ') rotateZ(' + parseInt(this.clingingPartner.dataset.degree) + 'deg);'; | |
| 307 | + break; | |
| 308 | + case 2: | |
| 309 | + this.clingingPartner.style.width = width + "px"; | |
| 310 | + this.clingingPartner.style.height = height + "px"; | |
| 311 | + this.clingingPartner.style.fontSize = (scaley * 100) + '%'; | |
| 312 | + break; | |
| 313 | + } | |
| 277 | 314 | } |
| 278 | 315 | mouseUpScale(evt) { |
| 279 | 316 | this.debuglog('mouseUpScale'); |
| @@ -0,0 +1 @@ | ||
| 1 | +テ<span style="font-size:150%;color:red">キ<strong style="font-size:200%">ス</strong>ト</span><br>Text | |
| \ No newline at end of file |
| @@ -0,0 +1 @@ | ||
| 1 | +テ<span style="font-size:20pt;color:red">キ<strong style="font-size:30pt">ス</strong>ト</span><br>Text | |
| \ No newline at end of file |
| @@ -0,0 +1,2 @@ | ||
| 1 | +テキスト | |
| 2 | +Text | |
| \ No newline at end of file |