マウスのクリックで円を 50% 縮小しようとしています。jQuery UI のスケール効果を使用してそれを行いました。
ディビジョンは
<div id='circle' class='circle'></div>
Jsは
var percent = 0.5;
$('#circle').click(function () {
var height = $(this).height();
var width = $(this).width();
var centerX = $(this).position().left + $(this).width()/2.0;
var centerY = $(this).position().top + $(this).height()/2.0;
$(this).effect( "scale", { percent: percent * 100 }, 1000, function () {
var newTop = centerY - (height * percent)/2.0;
var newLeft = centerX - (width * percent)/2.0;
$('#circle').offset({ 'top': newTop, 'left': newLeft });
$('#circle').css({'height': height * percent, 'width': width * percent });
});
});
そのコードは、円に次のようなテキストを追加するまで機能しました
<div id='circle' class='circle'>
<span class="title">Title</span>
</div>
タイトルは円とともに縮小されましたが、完成すると元のサイズに戻り、円は楕円形になりました。このフィドルを試してください: http://jsfiddle.net/marsant/Ycakg/
完了コールバックを手動で微調整する以外に、この問題を解決する適切な方法はありますか? ありがとう!