我在我的頁面上做了一個下拉菜單,得到的html元素,工作正常。但我想申請一個燈箱效果,就像當我從框中選擇一些元素出現像一個燈箱在我的頁面前面,現在它只顯示在我的html上,但是我想要應用一個lightbox效果,如果可能的話,我想要類似於這個插件的東西,但我可以看到只是在圖像中工作:http://getuikit.com/docs/lightbox.html選擇後的下拉菜單燈箱效果
Can誰來幫幫我?或者建議任何插件來做到這一點?
我的小提琴: http://jsfiddle.net/wjLXk/42/
更新之一:http://jsfiddle.net/wjLXk/43/
HTML:
<select id="mySelect" onchange="npup.doSelect(this);">
<option value="">Npup says 'select'</option>
<!-- the option values are suffixes for the elements to show -->
<option value="0">show one</option>
<option value="1">show two</option>
<option value="2">show three</option>
</select>
<!-- container for any elements that are to be in the game -->
<div id="mySpecialElements">
<!-- these have ids that end with and index for easy retrieval in "findeElement" function below-->
<div id="npup0" class="hidden">one div</div>
<div id="npup1" class="hidden">second div</div>
<div id="npup2" class="hidden">third div</div>
</div>
JS:
window.npup = (function (containerId, baseId) {
// save the container of your special element
var elementsContainer = document.getElementById(containerId);
var baseId = baseId;
function doSelect(select) {
// get value of select
var value = select.value;
// find element based on the value of the select
var targetDiv = findElement(value);
if (!targetDiv) { return;} // didn't find the element, bail
// do magic..
hideAll(elementsContainer);
showElement(targetDiv);
}
// retrieve some element based on the value submitted
function findElement(value) {
return document.getElementById(baseId+value);
}
// hide all element nodes within some parent element
function hideAll(parent) {
var children = parent.childNodes, child;
// loop all the parent's children
for (var idx=0, len = children.length; idx<len; ++idx) {
child = children.item(idx);
// if element node (not comment- or textnode)
if (child.nodeType===1) {
// hide it
child.style.display = 'none';
}
}
}
// display a certain element
function showElement(element) {
element.style.display = '';
}
// hide all on page load (might want some extra logic here)
hideAll(elementsContainer);
// export api to use from select element's onchange or so
return {
doSelect: doSelect
};
})('mySpecialElements', 'npup'); // give the routine a container id of your special elements, and the base id of those elements
謝謝簡單而快速的肯定 – Raduken