问题
I was developing a site and am using bootstrap, and jquery... I found out that bootstrap has modals that is exactly like fancybox, but realized it was not good enough, so I went ahead and got fancybox... I recently saw a website called PrimeDice, and I saw that they were also using fancybox, and I want to setup fancybox, like they did... If you look into their code, you can see that they are getting the fancybox like this...
<a href="/modals/faq.html" class="action-fancybox">faq</a>
Basically what is happening is that if you go to http://primedice.com/modals/faq.html you will see the plain text version of the fancy box. I want to do something similar to this, where it fetches the text or data of the fancybox from a different page... So basically have a folder called modals, and have a file called text.php and then fetch the information from that, and display it as a fancybox on my homepage... I hope you understand what I mean...
This is what their faq code looks like: http://pastie.org/8345073
回答1:
If you have this html
<a href="/modals/faq.html" class="action-fancybox">faq</a>
then use a jQuery code like this
jQuery(document).ready(function($){
$(".action-fancybox").fancybox({
type: "iframe"
});
});
Assuming that you have properly loaded jQuery as well as fancybox js and css files.
See it working in this JSFIDDLE
回答2:
You want to do it with something like that ?
$('.fancybox').click(function(e) {
e.preventDefault()
$.fancybox({
'content': $(this).attr('href'),
'type':'iframe'
});
来源:https://stackoverflow.com/questions/18938283/fancy-box-grab-from-url