四角のオブジェクトが、container
であるならば、大きさが縦:10px
横:10px
増えたとしたら、
containerの左上の角
のポジションを5px
減らしてあげれば良いです。
つまり
container.x ="大きさが増えた分の半分減らす"
container.y ="大きさが増えた分の半分減らす"
です。
--追記--
creatjs
は触ったことがないので、普通のjavascriptで、divを図形に見立てて例を書きますね。
creatjs
も中身はjavascript
なので同じ考え方だと思います。
コメントにて、基準点が画面中央位置じゃない時を気にされていたので、起点 top:400px; left:200px; にしてあります。
わかりやすいように、動作をまとめず一つずつ書いてますので参考にしてください。
javascript
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <style>
6
7 </style>
8 <script>
9 function kakudai($width){
10 var $target = document.getElementById('box');
11 var orgWidth = $target.clientWidth;//元の幅
12 var orgHeight = $target.clientHeight;//元の高さ
13 var rect = $target.getBoundingClientRect();//元の座標取得(左上の角)
14 var orgTop = rect.top;//元座標 y
15 var orgLeft = rect.left;//元座標 x
16
17
18 var zoom = 1.1;//ボタンを押すたび1.1倍
19 var nextWidth = (orgWidth*zoom);//次のサイズは元の幅×zoom
20 var nextHeight = (orgHeight*zoom);//次のサイズは元の高さ×zoom
21
22 var diffWidth = (nextWidth)-orgWidth;//差を求めてdiffWidthに代入
23 var diffHeight = (nextHeight)-orgHeight;//差を求めてdiffHeightに代入
24
25 $target.style.width = nextWidth+'px';//幅を変更
26 $target.style.height = nextHeight+'px';//高さを変更
27
28 var nextTop = (orgTop-(diffWidth/2))+'px';//大きくなった分の半分を引く
29 var nextLeft = (orgLeft-(diffHeight/2))+'px';//大きくなった分の半分を引く
30 console.log(nextTop);
31 console.log(nextLeft);
32 //場所を新しい場所に移動
33 $target.style.position = 'absolute';
34 $target.style.top = nextTop;
35 $target.style.left = nextLeft;
36 }
37
38 </script>
39</head>
40<body>
41 <input type="button" onclick="kakudai()" value="拡大">
42 <div id="box" style="position:absolute;top:400px;left:200px;width:100px;height:100px;background-color:lightgray;"></div>
43</body>
44</html>
--追記--
この絵でわかっていただけると思うのですが、、。