【发布时间】:2014-02-14 10:26:41
【问题描述】:
我需要一些帮助来使用 KineticJS (5.0.0.) 更改形状的不透明度。 在鼠标事件中,我想更改触发事件的形状的不透明度。每当形状悬停时,它就会变得可见( opacity 1.0 ),当它离开时,它变得不可见( opacity 0.0 )。每当我重绘指定形状的整个图层时,它都可以正常工作。
关键是,我无法重绘整个图层,因为它需要很长时间(约 300 个形状)。出于这个原因,我更改了一些代码,只绘制形状。
jsFiddle: http://jsfiddle.net/p39uH/2/(参见 HTML 的第 25 和 30 行)
var stage = new Kinetic.Stage({ 容器:'容器', 宽度:578, 身高:200 }); var layer = new Kinetic.Layer();
var pentagon = new Kinetic.RegularPolygon({ x: stage.width()/2, y: stage.height()/2, sides: 5, radius: 70, fill: 'red', stroke: 'black', strokeWidth: 4, opacity: 0.1 }); pentagon.on('mouseover', function() { this.opacity(0.3); this.draw(); // instead of layer.draw(); }); pentagon.on('mouseout', function() { this.opacity(0.0); this.draw(); // instead of layer.draw(); }); // add the shape to the layer layer.add(pentagon); // add the layer to the stage stage.add(layer);
(代码基于此:http://www.html5canvastutorials.com/kineticjs/html5-canvas-set-alpha-with-kineticjs/)
即使我在离开时将形状的不透明度设置为 0.0,您仍然可以看到它。每次悬停时,它都会变得越来越明显(我猜形状会被重绘)。
有没有办法(重新)绘制不透明度为 0.0 的形状而不绘制整个舞台和/或图层?
提前致谢。
【问题讨论】:
标签: javascript kineticjs opacity