将土坯边缘动画中心和预加载器水平和垂直居中

时间:2013-10-17 13:49:28

标签: adobe-edge

我制作了Adobe Edge动画。 现在我想将动画和预加载器居中,以便始终显示 在我的浏览器中以horizo​​naly和verticaly为中心。

请帮帮我。

我找到了以下帖子: http://forums.adobe.com/thread/979124?promoid=KBHBD

但对我来说没有任何作用。

1 个答案:

答案 0 :(得分:0)

我使用以下代码来居中并调整舞台大小以使其适合窗口。 如果您不想调整大小但只是居中,则可以简单地删除调整大小部分。 您可以将此代码粘贴到Stage组件的window.resize事件上(Window> Code> Stage> Event> Resize)。

var stageHeight = $("#Stage").height();
var stageWidth = $("#Stage").width();
// console.log("stageHeight " + stageHeight);
// console.log("stageWidth " + stageWidth);
var ratio = stageWidth / stageHeight;
var bodyHeight = $(window).height();
var bodyWidth = $(window).width();
// console.log("bodyHeight " + bodyHeight);
// console.log("bodyWidth " + bodyWidth);
var bodyRatio = bodyWidth / bodyHeight;
var newStageHeight = bodyHeight;
var newStageWidth = bodyWidth;
var leftPos = 0;
var topPos = 0;
// fit width
if (bodyRatio < ratio) {
    newStageWidth = bodyWidth;
    newStageHeight = newStageWidth / ratio;
    topPos = 0.5 * (bodyHeight - newStageHeight);
}
// fit height
else if (ratio < bodyRatio) {
    newStageHeight = bodyHeight;
    newStageWidth = newStageHeight * ratio;
    leftPos = 0.5 * (bodyWidth - newStageWidth);
}
// console.log("newStageHeight " + newStageHeight);
// console.log("newStageWidth " + newStageWidth);
$("#Stage").height(newStageHeight);
$("#Stage").width(newStageWidth);
$("#Stage").css("left", leftPos + 'px');
$("#Stage").css("top", topPos + 'px');