1

このコードは Kineticjs を使用しています。画像の 1 つにマウスオーバー イベントとマウスアウト イベントを使用しています。レイヤーには 2 つの画像があります。そのうちの1つだけを非表示にしたい。画像ごとに個別のレイヤーを作成する必要がありますか?

img.onload = function(){
                    var image = new Kinetic.Image({
                        image: img,
                        name:'iconImage',
                        width: 50,
                        height: 50,
                        //draggable: true,
                        //visible:true,
                        listening:true
                    });
                    var image2 = new Kinetic.Image({
                        x:100,
                        y:100,
                        image: img,
                        name:'iconImage',
                        width: 50,
                        height: 50,
                        //draggable: true,
                        //visible:true,
                        listening:true
                    });
                iconLayer.add(image).add(image2);
                stage.add(iconLayer);
                //stage.draw();


                image.on('mouseover',function(){
                    image.hide();

                    iconLayer.clear();
                    //iconLayer.draw();

                });

                image.on('mouseout',function(){
                    //iconLayer.clear();
                    //image.show();
                    //iconLayer.draw();

                    image.show();
                    iconLayer.draw();

                    //stage.draw();
                });

                }

hide() 関数と show() 関数を使用する最良の方法はどれですか?

4

4 に答える 4

2

別のレイヤーは必要ありません。

myShape.hide() と myShape.show() を使用するだけです

于 2013-05-14T19:57:08.843 に答える
1

markE が言ったように、使用できますがhide()show()で形状を非表示/表示した後、レイヤーを再描画することを忘れないでくださいstage.draw()

于 2013-05-15T06:31:13.027 に答える
0

上記の回答を読んで、私の回答を理解してください。

私のコードでは、image1 に「mouseover」イベントを追加し、image1 を非表示にしています。次に、image1 に「mouseout」を追加し、image1 を表示します。hide-draw と show-draw を実行すると、画像がちらつき、完全に消えません。画像がもう存在しないため、Kinetic は hidden=mouseout を取ると推測しています。

ただし、image1 の「mouseover」イベントで image2 を非表示にすると、hide-draw および show-draw メソッドで問題なく動作します。このシナリオは私にとってはうまくいきます。助けてくれてありがとう

于 2013-05-15T12:11:39.933 に答える