我使用magnific popup插件在div中显示包含HTML内容的模态窗口。
当用户触发弹出窗口时,我想随机显示一些div。
但是......由于我的javascript技巧不佳,我不确定如何使用magnific's API来实现这一点。 (说实话,我甚至不确定从哪里开始!)。
有人对如何使用API达到我需要的任何建议吗?
再次感谢..
HTML用作触发器:
<a href="#popup-1" class="open-popup">No</a>
HTML内容示例(其中一个要随机显示):
<div id="popup-1" class="mfp-hide">
Content here
</div>
<div id="popup-2" class="mfp-hide">
Content here
</div>
<div id="popup-3" class="mfp-hide">
Content here
</div>
JQuery用于初始化大胆的弹出窗口:
$('.open-popup').magnificPopup({
removalDelay: 300,
mainClass: 'mfp-fade',
closeOnContentClick: true,
closeBtnInside: true
});
我发现this code可以帮助进行随机div选择? :
var divs = $("div.Popup").get().sort(function(){
return Math.round(Math.random())-0.5; //random so we get the right +/- combo
}).slice(0,4)
$(divs).appendTo(divs[0].parentNode).show();