javascript ColorBox - 错误:cboxElement 缺少设置对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14376774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ColorBox - Error: cboxElement missing settings object
提问by Techie
What I'm trying to do is to play a video inside ColorBoxlightbox.
我想要做的是在ColorBox灯箱中播放视频。
My HTML code is as follows. When I click on the link it should play the video.
我的 HTML 代码如下。当我点击链接时,它应该播放视频。
<a href="http://cdn-azu-ns.viddy.com/media/video/0b2b103a-0c40-48a4-877a-64645ef5a0ae-high.mp4?t=634914421568400000" target="_blank" class="photo_link cboxElement iframe">Video</a>
What I do with Colorbox is as below. Load the video into lightbox.
我对 Colorbox 的处理如下。将视频加载到灯箱中。
jQuery(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
It gives me the below error.
它给了我以下错误。
Error: cboxElement missing settings object
ScreenShot
截屏
What should I do to fix this ? Given that there are no js errors except above one. jQuery is included correctly.
我该怎么做才能解决这个问题?鉴于除了上述错误之外没有任何 js 错误。jQuery 被正确包含。
回答by BakaKuna
I had the same problem. I'm having a hard time trying to understand why exactly, but somewhere the colorbox is running in to a conflict because it also uses the name 'iframe' internally. Somehow this is causing a conflict when the classname 'iframe' is used as the class by which the function is called.
我有同样的问题。我很难确切地理解为什么会这样,但是颜色框在某个地方遇到了冲突,因为它也在内部使用了名称“iframe”。当类名“iframe”用作调用函数的类时,这会以某种方式导致冲突。
In my case changing
在我的情况下改变
jQuery(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
to:
到:
jQuery(".photo_link").colorbox({iframe:true, width:"80%", height:"80%"});
worked.
工作。
回答by Alfonso
Well this worked for me. Even though everything was in place and all the code was generated in the backend, for some reason colorbox wasn't picking up the links properly because on my page the link was inside a div that shows/hide on mouseover. Anyway, the way it worked for me was this one:
嗯,这对我有用。即使一切就绪并且所有代码都是在后端生成的,但由于某种原因,colorbox 没有正确获取链接,因为在我的页面上,链接位于一个 div 内,该 div 在鼠标悬停时显示/隐藏。无论如何,它对我有用的方式是这样的:
$(".iframe").live('click', function(e){
$(this).colorbox({href: $(this).attr('href'), iframe:true, innerWidth:640, innerHeight:480, open:true});
e.preventDefault();
return false;
});
In this way you rebind the actions to the element and then forces colorbox to open the link.
通过这种方式,您将操作重新绑定到元素,然后强制 colorbox 打开链接。
I hope it works for you and it isn't too late.
我希望它对你有用,现在还为时不晚。
PS: If you're using jQuery 1.9+ you must use on instead of live
PS:如果您使用的是 jQuery 1.9+,则必须使用 on 而不是 live
回答by Chris
I ran into this same error and solved it by removing a duplicate call to colorbox. I had included both the library as well as my colorbox function in two separate include files. I figured it must be a duplicate because I had to close each colorbox window twice after it launched.
我遇到了同样的错误,并通过删除对 colorbox 的重复调用来解决它。我已经在两个单独的包含文件中包含了库和我的 colorbox 函数。我认为它一定是重复的,因为我必须在启动后关闭每个颜色框窗口两次。
Check your code and make sure that the jquery.colorbox-min.js is only included once, as well as your function that calls it. In my case, my function was simple:
检查您的代码并确保 jquery.colorbox-min.js 只包含一次,以及调用它的函数。就我而言,我的功能很简单:
$(document).ready(function(){
$("a.single_image").colorbox();
$("a.link_preview").colorbox({iframe:true, width:"80%", height:"90%"});
});
After removing the duplicate calls, the problem went away. Hope it helps!
删除重复调用后,问题就消失了。希望能帮助到你!
回答by Giancarlo Colfer
I experienced this error Error: cboxElement missing settings objectwhen making a second jQueryon document ready function callafter the initial on document ready function callthat holds the colorbox parameters.
我遇到了这个错误Error: cboxElement missing settings object在保存colorbox 参数的初始文档就绪函数调用之后,在文档就绪函数调用上进行第二个jQuery时。
My situation:
我的情况:
On my pages I use and call just one external .js file that holds all my code.
Inside the external .js file I have the colorbox parameterswithin a jQueryon document ready function.
On the troubled page (page with cboxElement missing settings object
error), immediately following the external .js file I had some
jQuerycode that used the on document ready function: $(function(){});
在我的页面上,我只使用和调用一个包含我所有代码的外部 .js 文件。
在外部 .js 文件中,我在文档就绪函数上的 jQuery 中有colorbox 参数。
在有问题的页面(带有cboxElement 缺少设置对象
错误的页面)上,紧跟在外部 .js 文件之后,我有一些使用文档就绪函数的
jQuery代码:$(function(){});
My problem:
我的问题:
This second on document ready call caused and triggered the error Error: cboxElement missing settings objectfor me.
这第二个文档就绪调用导致并触发了错误Error: cboxElement对我来说缺少设置对象。
My solution:
我的解决方案:
The fix was as easy as changing the troubled pages code from using jQuery'son document ready functionto using Javascript'snative self-executing anonymous function.
修复就像将有问题的页面代码从使用jQuery 的文档就绪函数更改为使用Javascript 的本机自动执行匿名函数一样简单。
(function(){
})();
Sure enough the error Error: cboxElement missing settings objectwent away and everything works perfect!
果然错误 Error: cboxElement missing settings object消失了,一切正常!