我要實現多個彈出窗口的問題。我從網上獲得這個腳本,當我申請一個彈出窗口時是正確的,但如果我做了這個副本,這是正確的。你可以看到它:Dendrosite。在距左菜單(Sinopsi/Fitxa/Autors)我在一個(Sinopsi)實施正確地將,但現在我可以實現與其他(Fitxa/Autors)如何實現多個彈出窗口?
HTML:
<li class="sinopsi"><a id="go"><span></span></a></li>
<div id="popupContact">
<a id="popupContactClose"></a>
<h1></h1>
<h3>
<br/><br/>
</h3>
</div>
<div id="backgroundPopup"></div>
的Javascript:
var popupStatus = 0; //loading popup with jQuery magic! function loadPopup(){ //loads popup only if it is disabled if(popupStatus==0){ $("#backgroundPopup").css({ "opacity": "0.7" }); $("#backgroundPopup").fadeIn("fast"); $("#popupContact").fadeIn("fast"); popupStatus = 1; } } //disabling popup with jQuery magic! function disablePopup(){ //disables popup only if it is enabled if(popupStatus==1){ $("#backgroundPopup").fadeOut("fast"); $("#popupContact").fadeOut("fast"); popupStatus = 0; } } //CONTROLLING EVENTS IN jQuery $(document).ready(function(){ //LOADING POPUP //Click the button event! $("#go").click(function(){ //centering with css //load popup loadPopup(); }); //CLOSING POPUP //Click the x event! $("#popupContactClose").click(function(){ disablePopup(); }); //Click out event! $("#backgroundPopup").click(function(){ disablePopup(); }); //Press Escape event! $(document).keypress(function(e){ if(e.keyCode==27 && popupStatus==1){ disablePopup(); } }); });
和CSS:
#backgroundPopup{ display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:100%; width:100%; top:0; left:0; z-index:1; } #popupContact{ margin-top: -104px; margin-left:102px; display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:288px; width:600px; z-index:9; padding:12px; background-color: #333; filter: alpha(opacity=20); opacity: .5 } #popupContact h1{ font-family:Arial, Helvetica, sans-serif; font-size:20px; color:#FFF; text-shadow: 0px 1px 1px #000; padding-bottom:10px; margin-bottom:30px; border-bottom-width: 1px; border-bottom-style: solid; } #popupContact h3{ font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFF; text-align: justify; } #popupContactClose{ font-size:18px; line-height:14px; right:6px; top:4px; position:absolute; color: #ffeb70; font-weight:700; display:block; cursor: pointer; font-family: Arial, Helvetica, sans-serif; }
謝謝!
感謝Quang !!! – aleish76 2011-03-21 23:14:58
有沒有辦法使用彈出類代替多個ID喜歡popup1 popup2 popup3?我的問題是在數百個div中設置多個ID。 – abhils 2018-01-19 05:54:59
@abhils,是的,你可以使用jQuery環通與元素'.popup'類和你想他們什麼。 – 2018-01-29 16:19:07