環境
Riot.js経験者大歓迎ですが、JS使用者であれば理解いただける内容であると思います。
実現したい事
modal表示 → 画面のどこかclickでmodal閉じる
(現状はmodalそのものをclickしても閉じない)
コード
this.modalのtrue・falseでmodal開閉を操作しています
//modalがopenする関数 modalOpen(){ ShowHide.begins(function(){ this.modal = true; this.update(); }.bind(this), function(){ //(②)画面上modal以外をクリックすると起動 this.modal = false; this.update(); }.bind(this)); //**追加部分 ここでmodalが開いているか確認し、上のbeginsが起動される if (!ShowHide.isShow()){ Event.listenByShowHide(ShowHide); } } //modalのブロック要素clickでこの関数起動(modal閉じるように) close(){ this.modal = false; this.update(); } //begins(関係するメソッド追記) begins(Show, Hide){ this._Show = Show || null; this._Hide = Hide || null; return this; } //listenByShowHide(関係するメソッド追記) listenByShowHide(showHide, release=true){ showHide.show(); const element = showHide.getElement(); const fn = function(){ showHide.hide.call(showHide); }; this.listen(element, fn, release); }
これでも閉じますが、次にmodalOpen()を起動させるとbegins method第二引数目(②部分)が起動して、modalが表示されない。
→close()が起動される = beginsの第二引数目の関数が起動される。 にしたい、しかしその方法が不明なのでこちらで質問させていただきました。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。