我在我的页面上做了一个下拉菜单,得到的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