我有一个边缘动画文档,我想在用户触摸舞台上的任何位置时创建/触发符号。我希望符号的中心位于点击时指针位于舞台上的位置。
我知道如何使用javascript确定点击x,y坐标,但如何在该位置放置符号?
答案 0 :(得分: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 + "%");