0

我有一个边缘动画文档,我想在用户触摸舞台上的任何位置时创建/触发一个符号。我希望符号的中心是点击时他们的指针在舞台上的位置。

我知道如何使用 Javascript 确定点击 x,y 坐标,但是如何在该位置放置符号?

4

1 回答 1

0

我是这样做的:

//Create symbol on stage. 
//The number 1 indicates the position in the list 
//of the symbol instances on the stage, 
//like the one you see in the right panel called "Elements".
//Use it to set the z-index (position elements in front or in background).
var myNewSymbol = sym.createChildSymbol("myNewSymbol", "Stage", 1);
var x = e.pageX;
var y = e.pageY;

// I wanted position to be in percentage
var bodyHeight = $(window).height();
var bodyWidth = $(window).width();
var xPercent = 100 * x / bodyWidth;
var yPercent = 100 * y / bodyHeight;

//Set the position
myNewSymbol.getSymbolElement().css("position", "absolute");
myNewSymbol.getSymbolElement().css("left", xPercent + "%");
myNewSymbol.getSymbolElement().css("top", yPercent + "%");
于 2013-06-28T09:59:57.090 回答