Youtube fancybox will not work

末鹿安然 提交于 2019-12-20 07:07:44

问题


I am currently trying to make a fancybox with a youtube video inside it. I currently have a couple more fancyboxes on the page but can not seem to get this fancybox to work,the other fancyboxes have the class of fancybox-iframe or fancybox depending on the content if this is any help.

Below is the link that I want to add fancybox to.

<a href="http://youtu.be/krlR2-YGk4sI" target="_blank"><span class="cta floatL">through the eyes of a bigsmile advert</span><span class="playIco floatL"></span></a>

This is the iframe that I am putting into my fancybox. Can somebody please help me?

<iframe width="420" height="345" src="http://www.youtube.com/embed/krlR2-YGk4sI?autoplay=1" frameborder="0" allowfullscreen></iframe>

Thanks


回答1:


You don't need to place your video inside an iframe. The only html you need is the link to your video like :

<a class="fancybox" href="http://youtu.be/krlR2-YGk4sI" target="_blank">Open youtube</a>

Notice the class fancybox in the <a> tag (you can use any other class name, just make sure you bind the correct selector to fancybox)

Then include the fancybox media helper in your page :

<script type="text/javascript" src="path/to/fancybox/files/helpers/jquery.fancybox-media.js"></script>

... and add the helpers media API option to your custom script like :

$(document).ready(function () {
    $('.fancybox').fancybox({
        helpers: {
            media: {}
        }
    });
});

See JSFIDDLE



来源:https://stackoverflow.com/questions/20817171/youtube-fancybox-will-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!