0

I'm using Yui to build a "popup" menu that works a bit differently with the mouse than usual. This is not a ContextMenu, because I want it to respond to left clicks, and the ContextMenu seems bent on responding to right clicks.

Following the examples, if I do this, the menu comes up and everything is close to how I want it:

YAHOO.util.Event.addListener(myClickTarget, 'click', myThingGotClicked);

In my myThingGotClicked function, I manually set the menu's position and show() it.

My problem is that I want to "bind" the menu visibility to the state of the mouse button. That is, on a mouseDown, I want the menu to come up, and on a mouseUp, I want the menu to disappear (selecting the active item, if any). So, listening to the 'click' event doesn't do the right thing, because a "click" is only sent after mouseUp.

The "obvious" solution is to do this:

YAHOO.util.Event.addListener(myClickTarget, 'mousedown', myThingGotClicked);

But this doesn't work. Stepping through in a debugger, you can see that it does actually bring up the menu on a mousedown, but then something immediately hides the menu. At full speed, it looks like nothing happens at all.

Any thoughts?

4

2 に答える 2

1

問題は、MenuManager クラスがドキュメント レベルで mousedown イベントをリッスンし、表示されているすべての Menu インスタンスを非表示にすることです。したがって、独自の種類の Menu 実装を構築しているため、ハンドラ内で mousedown イベントの伝播を停止して、MenuManager がイベントを処理しないようにする必要があります。ここにいくつかの疑似コードがあります:

var myThingGotClicked = function (event) {

    YAHOO.util.Event.stopPropagation(event);

    // Do other stuff

};

YAHOO.util.Event.on(myClickTarget, 'mousedown', myThingGotClicked);
  • トッド
于 2009-01-22T23:37:29.943 に答える
0

メニューがポップアップするので、もう少し近いですが、メニューで選択しようとすると、その下のページのテキスト選択がちょっとおかしくなります. マウスを放してもメニューが下がらないので、マウスアップ ハンドラも追加する必要があると思います。

ここで本当に欲しいのは、Mac OS のすべてのバージョンのメニューのように機能するメニューです (最近、OS X が「クリックしてメニューを固定」する機能をデフォルトの動作に追加するまで)。

于 2009-01-26T19:32:51.407 に答える