Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

javascript - Vimeo API方法中的变量“ undefined”(Variable `undefined` in Vimeo API method)

So I have embedded a vimeo video in my Angular 8 app and am now trying to trigger some animation after the video starts playing and once its ended.(因此,我已在Angular 8应用程序中嵌入了一个vimeo视频,现在尝试在视频开始播放并结束后触发一些动画。)

Essentially if screen width is <800 , the variable isMobile is true .(本质上,如果屏幕宽度<800 ,则变量isMobiletrue 。) Next I have the vimeo play method being called which checks if isMobile is true , and sets load_completed (which is the animation trigger) to true .(接下来,调用load_completed play方法,该方法检查isMobile是否为true ,并将load_completed (这是动画触发器)设置为true 。) The isssue is that my variable isMobile returns undefined , why is that?(问题是我的变量isMobile返回undefined ,为什么呢?) isMobile = false; constructor() { } ngOnInit() { this.innerWidth = window.innerWidth; console.log(this.innerWidth); if (this.innerWidth < 800) { this.isMobile = true; } var iframe = document.querySelector('iframe'); var player = new Vimeo.Player(iframe); player.on('play', function() { //isMobile returns undefined why? console.log(this.isMobile); if (this.isMobile) { this.load_completed = true; } console.log('Played the video'); }); player.on('ended', function(data) { console.log('Video ended'); }); }   ask by kontenurban translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using arrow function as follows , here is the explanation(尝试如下使用arrow function ,这是explanation)

player.on('play',()=>{ console.log(this.isMobile); })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...