をあなたはちょうどこの目的のために全体のjQuery UIライブラリを追加したくないかもしれません。もし私がここにいるなら、あなたはそれをどうやってやるの?
したがって、入力を「集中」すると、その入力を「opensModal」と呼ぶことができます。モーダルを開きたいとします。 「長い」コードにもかかわらず、かなりシンプルで自明です。実際には、そのほとんどはモーダル/モーダル外観をよりきれいにするためだけにあります。ここに私達は行く:
HTML:
<!-- the input -->
<input class="opensModal" type="text" />
<!-- the modal and its overlay -->
<div class="modalOverlay is-inactive">
<div class="modal">
<input type="checkbox" />
<input type="checkbox" />
<button>Ok</button>
<button>Cancel</button>
</div>
</div>
CSS:
.modalOverlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
-webkit-transition: 0.6s;
}
.modalOverlay.is-inactive {
visibility: hidden;
background: rgba(0, 0, 0, 0);
}
.modalOverlay.is-active {
visibility: visible;
background: rgba(0, 0, 0, 0.4);
}
.modal {
margin: 100px auto;
background: #fff;
width: 100px;
padding: 20px;
-webkit-transition: 0.4s 0.6s;
}
.modalOverlay.is-inactive .modal {
visibility: hidden;
opacity: 0;
-webkit-transform: scale(0.1);
}
.modalOverlay.is-active .modal {
visibility: visible;
opacity: 1;
-webkit-transform: scale(1);
}
jQueryの(ジャバスクリプト)
(function() {
var $modal = $('.modalOverlay'),
openModal = function() {
$modal
.removeClass('is-inactive')
.addClass('is-active');
},
closeModal = function() { //use it wherever you want
$modal
.removeClass('is-active')
.addClass('is-inactive');
},
onDocReady = function() {
$('.opensModal').on('focus', openModal);
};
$(onDocReady);
})();
ここでフィドルです:http://jsfiddle.net/2edPZ/3/
あなたはjQueryのUIを使用しています? –
はい、私はこのプロジェクトでJQueryを使用しています。 –
[jQuery UI](http://jqueryui.com)はjQueryの上にあるライブラリです。それがあなたが意味するものなのかそうでないのかは分かりません。それはモーダルダイアログを持っています。人々が手助けをしたい場合は、たとえそれが機能しなくても、あなたが持っているコードを投稿してください。 –