繁体   English   中英

在dynamicjs中创建变量

[英]Creating variable in kineticjs

小提琴中 ,将图像放入容器后,每个图像都存储在名为image的变量中,但是我想将每个放置的图像存储在不同的变量名称中。它不起作用(image1.onload),我该怎么办?

   if($(ui.helper).hasClass("sticky")){
            console.log();
             var image = new Kinetic.Image({
                name: data,
                id: "image"+(imageCount++),
                x: $stageContainer.width() / 2 - ($(ui.helper).width() / 2),
                y: $stageContainer.height() / 2 - ($(ui.helper).height() / 2),
                image: theImage,
                draggable: false
            });
        }else{

            var image1 = new Kinetic.Image({
                name: data,
                id: "image"+(imageCount++),
                x: x,
                y: $stageContainer.height() / 2 - ($(ui.helper).height() / 2),
                image: theImage,
                draggable: true
      });
    }

我认为使用数组可能是要走的路。

var images = [];

images.push(new Kinetic.Image({
    name: data,
    id: "image"+(imageCount++),
    x: x,
    y: $stageContainer.height() / 2 - ($(ui.helper).height() / 2),
    image: theImage,
    draggable: true
}))

您可以使用数组中的索引来引用它们,然后像images[0].onload

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM