jQuery和Vimeo Froogaloop API [英] jQuery and Vimeo Froogaloop API
问题描述
我正在尝试使用它与jQuery,我认为WordPress版本的jQuery是搞砸了code> $ f 快捷方式。为什么这不工作?
var vimeoPlayer = {
init:function(){
var vimeoPlayers = document.querySelectorAll('iframe'),
player;
jQuery('iframe.vimeo-player')。each(function(index,iframe){
player = vimeoPlayers [index];
$ f(player).vimeoPlayer .addEvent('ready',vimeoPlayer.ready);
});
},
addEvent:function(element,eventName,callback){
if(element.addEventListener){
element.addEventListener(eventName,callback,false) ;
}
else {
element.attachEvent(eventName,callback,false);
}
},
ready:function(player_id){
alert(player_id);
}
}
jQuery(document).ready(function($){
vimeoPlayer.init.call();
});
您可以在中看到它在temp.woodshop.tv/?work /?dickies-campaign /?
。
我收到这个错误:
TypeError:表达式的结果$ f(player).vimeoPlayer'[undefined]不是一个对象。
一个问题是addEvent既是您定义的函数,也是$ f(player)对象的一种方法。看来你对这两个人感到困惑。 $ f(player)对象的addEvent方法只需要两个参数,即播放器事件的名称和要调用的函数。它应该用作$ f(你的iframe).addEvent('vimeo event',your_function);
你的addEvent函数将统一IE和W3C方法之间的事件。这是不需要的,因为你使用jQuery。 jQuery(any).click()做同样的事情。我没有看到您需要的片段的任何部分,但是如果你这样做,我只需要使用jQuery方法。
此外,视频播放器对象应该是$ f(播放器)而不是$ f(播放器).vimeoPlayer
尝试这个
jQuery('iframe.vimeo-player')。each(function(){
$ f(this).addEvent('ready',ready);
});
另外需要注意的是,任何额外的播放器事件都需要从您的回拨函数中添加。例如:
function ready(player_id){
$ f(player_id).addEvent('play',play );
$ f(player_id).api('play');
alert(Ready !!!);
}
function play(){
alert(Playing !!!);
}
我很难在Vimeo的Froogaloop api上找到我想要的信息但是在刷新 Vimeo Froogaloop API游乐场后,可以打一打时间我开始了解它的运作方式。
祝你好运!
I'm building a plugin to WordPress and so far so good with the PHP library. But I am having some issues with the JavaScript API.
I'm trying to use it with jQuery, and I think the WordPress version of jQuery is messing with the $f
shortcut. Why wouldn't this work?
var vimeoPlayer = {
init: function() {
var vimeoPlayers = document.querySelectorAll('iframe'),
player;
jQuery('iframe.vimeo-player').each(function(index, iframe){
player = vimeoPlayers[index];
$f(player).vimeoPlayer.addEvent('ready', vimeoPlayer.ready);
});
},
addEvent: function(element, eventName, callback) {
if (element.addEventListener) {
element.addEventListener(eventName, callback, false);
}
else {
element.attachEvent(eventName, callback, false);
}
},
ready: function(player_id) {
alert(player_id);
}
}
jQuery(document).ready(function($){
vimeoPlayer.init.call();
});
You can see it in action at temp.woodshop.tv/?work/?dickies-campaign/?
.
I get this error:
TypeError: Result of expression '$f(player).vimeoPlayer' [undefined] is not an object.
One issue is that addEvent is both a function that you've defined and also a method of the $f(player) object. It appears that you're confusing the two. The addEvent method of the $f(player) object only takes two arguments, the name of the player event and the function to be called. It should be used as $f(your-iframe).addEvent('vimeo event', your_function);
Your addEvent function will unify events between IE and W3C methods. It's not needed because you're using jQuery. jQuery(whatever).click() does the same thing. I don't see any part of your snippet where you need it but if you do, I'd just use the jQuery method.
Also, the video player object should be $f(player) instead of $f(player).vimeoPlayer
Try this
jQuery('iframe.vimeo-player').each(function(){
$f(this).addEvent('ready', ready);
});
Another thing to note is that any additional player events need to be added from your ready callback function. For example:
function ready(player_id){
$f(player_id).addEvent('play', play);
$f(player_id).api('play');
alert("Ready!!!");
}
function play(){
alert("Playing!!!");
}
I've had a hard time finding the info I want on Vimeo's Froogaloop api but after scouring Vimeo Froogaloop API Playground about a dozen times I'm starting to get the idea of how it works.
Good luck!
这篇关于jQuery和Vimeo Froogaloop API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!