0

ここで私の問題の解決策を見つけることができませんでした...

私は基本的に、ユーザーが画像を必要な表示部分に移動できる Facebook サムネイル エディターのようなものを作成しています。

画像を90度間隔でのみ回転できるようにしたいことを除いて、うまく機能します。ここで問題が発生します。

ユーザーが回転ボタンを押すと、移動を表示ボックス内に制限する contanier div が jQuery を介して更新されます。数学によると、制約する div の寸法は正しいようです。ただし、回転した画像は、制約する div 内で適切に移動しません。他の次元に縛られているようです。場合によっては、制約する div の境界の外に出ます。

制限する div 内で回転した画像を自由に移動するにはどうすればよいですか? transform-origin で何かをする必要がありますか? 私の原点は、回転に関係なく常に画像の中心にあるはずですが?

jQuery:

var rotValue = 0;

$("a[id='rotate']").click(function(e) {

    rotValue +=90;          
    if (rotValue == 360) {rotValue = 0;}

    var wd = $('#photo-in-edit').width();
    var ht = $('#photo-in-edit').height();      

    $('#photo-in-edit').css('-moz-transform', 'rotate('+rotValue+'deg)');
    $('#photo-in-edit').css('-webkit-transform', 'rotate('+rotValue+'deg)');
    $('#photo-in-edit').css('-o-transform', 'rotate('+rotValue+'deg)');
    $('#photo-in-edit').css('-ms-transform', 'rotate('+rotValue+'deg)');


    if ((rotValue == 0) || (rotValue == 180)){
        createCont(wd, ht);  //calls the function below to resize the container
    } else {        
        createCont(ht, wd);
    }

    e.preventDefault();
    return false;

});

function createCont (w, h) {

    var containerHeight, containerTop, containerWidth, containerLeft;

    //the dimensions of my viewable area are 600 x 400  
    var xOverflow = (w - 600);
    var yOverflow = (h - 400);

    if (xOverflow < 0) {containerHeight = 400;containerTop = 0;}
    else {containerHeight = ((h * 2) - 400);containerTop = (yOverflow*-1);}

    if (yOverflow < 0) {containerWidth = 600;containerLeft = 0;}
    else {containerWidth = ((w * 2) - 600);containerLeft = (xOverflow*-1);}

    $('#photo-container').css('top', containerTop+"px");
    $('#photo-container').css('height', containerHeight+"px");
    $('#photo-container').css('left', containerLeft+"px");
    $('#photo-container').css('width', containerWidth+"px");
    $('#photo-in-edit').css('top', "");
    $('#photo-in-edit').css('left',""); 

}   

HTML:

<div class="photo-edit-box" >
    <div id="photo-container" >
        <img id="photo-in-edit" src="http://upload.wikimedia.org/wikipedia/commons/c/ca/Oud_Poelgeest_Oegstgeest.jpg" />
    </div><!--photo-container-->
</div><!--photo-edit-box-->
4

1 に答える 1