【发布时间】:2015-04-21 10:00:45
【问题描述】:
我正在使用以下代码在 fancybox 中打开一个 youtube 视频。
$("#videos a.fancybox").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 1280,
'height' : 720,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
但是我希望它在窗口出现之前做一些事情。我会把它包括在下面。
$("#videos a.fancybox").click(function() {
$.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 1280,
'height' : 720,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
},
beforeShow: function () {
var id = this.element.attr("id");
alert(id);
}
});
return false;
});
基本上,它会抓取 ID 中的内容并尝试提醒它。使用这段代码,窗口将无法打开,并将重定向到 youtube。如果我输入alert("ohi"); 之类的内容,它将正确显示,但我必须删除 var。有人知道为什么吗?如果我将它包含在另一个 fancybox 代码中,它会起作用,例如:
$('#photos a.fancybox').fancybox({
type: 'iframe',
beforeShow: function () {
var id = this.element.attr("id");
alert(id);
}
});
为什么它不适用于视频?
提前致谢。
【问题讨论】:
-
什么版本的fancybox?
-
您好。现在是 2.1.5。
标签: jquery youtube callback fancybox fancybox-2