简体   繁体   English

如果属性等于(Kinetic.js)

[英]If attribute equals (Kinetic.js)

I'm very new to Kinetic.js and I can't find a solution to my problem. 我是Kinetic.js的新手,找不到解决我问题的方法。 I create a new kinetic.line here: 我在这里创建一个新的dynamic.line:

var shape = new Kinetic.Line({
color: area.colour
});

And I want to use the color attribute in an if loop: 我想在if循环中使用color属性:

stage.on('mouse down', function(evt) {
var shape = evt.targetNode;
if (shape.color == 'red') {
    window.location.href = 'http://www.google.com';
}
});

This doesn't work, what do I need to do? 这行不通,我该怎么办?

There is no color attribute. 没有颜色属性。 Use 'fill' instead. 请改用“填充”。 Then use 'mousedown' event instead of 'mouse down'. 然后使用“ mousedown”事件而不是“ mouse down”事件。

var shape = new Kinetic.Line({
fill: area.colour
});

stage.on('mousedown', function(evt) {
var shape = evt.targetNode;
    if (shape.getFill() === 'Red') {
        window.location.href = 'http://www.google.com';
    }
});

Take a look at the documentation http://kineticjs.com/docs/Kinetic.Line.html . 看一下文档http://kineticjs.com/docs/Kinetic.Line.html

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

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