2013-10-18 25 views
0

我使用波纹管的js代码

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390}); 
     $(".callbacks").colorbox({ 
     onOpen:function(){ alert('onOpen: colorbox is about to open'); }, 
     onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, 
     onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, 
     onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, 
     onClosed:function(){ alert('onClosed: colorbox has completely closed'); } 
     }); 
    }); 
    </script> 

那么这个波纹管的错误来

TypeError: $(...).colorbox is not a function [Break On This Error]

$(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390}); 

当我点击视频。直接链接它在页面而不是灯箱效果中打开

+2

您是否包含该插件? –

+3

jQuert冲突.. http://stackoverflow.com/questions/3188262/jquery-noconflict –

+2

是包含的 没有冲突 只有2个js文件存在 http://www.statcounter.com/counter/counter .js文件 和 www.google-analytics.com/analytics.js – Ras4U

回答

2

这只是我可以给出的最精简的示例,将您的代码与某些采样来自网站的代码(特别是来自此页面的JS和CSS:http://www.jacklmoore.com/colorbox/example2/)。请注意,/ public是我在我的设置中存储外部资产的地方。

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
    <link rel="stylesheet" href="/public/colorbox.css" /> 
    </head> 
    <body> 
    <a class="youtube cboxElement" href="http://www.youtube.com/embed/VOJyrQa_WR4?rel=0&amp;wmode=transparent">Flash/Video (Iframe/Direct Link To YouTube)</a> 
    <script src="/public/jquery-1.10.2.js"></script> 
    <script src="/public/jquery.colorbox.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390}); 
     $(".callbacks").colorbox({ 
     onOpen:function(){ alert('onOpen: colorbox is about to open'); }, 
     onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, 
     onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, 
     onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, 
     onClosed:function(){ alert('onClosed: colorbox has completely closed'); } 
     }); 
    }); 
    </script> 
    </body> 
    </html> 

该代码产生一个链接,点击该链接后,将打开一个带有您的尺寸规格的lightbox版视频。

+0

所以是:这不是什么原因不工作,因为链接是在写入js代码之后编写的? –

相关问题