Reputation: 63
I am working with the following script and would ideally like to get two functions triggered on if (callOnce), I have tried the following (Example 1. - sync function) this works fine but where I add two functions, (example 2. - Sync and Fade functions). They both fail to produce a result. Any help appreciated...
Example 1.
function aperture() {
"use strict";
var media = document.getElementsByTagName("video")[0];
if ((media.duration - media.currentTime) < 475)
if (callOnce) {
sync();
callOnce = false;
}
}
Example 2.
function aperture() {
"use strict";
var media = document.getElementsByTagName("video")[0];
if ((media.duration - media.currentTime) < 475)
if (callOnce) {
sync();
fade();
callOnce = false;
}
}
Upvotes: 0
Views: 49
Reputation: 10450
Please try this:
var aperture = (function() {
var called = false;
return function() {
if(called) return;
var media = document.getElementsByTagName("video")[0];
if ((media.duration - media.currentTime) < 475) {
sync();
fade();
}
called = true;
}
})();
Upvotes: 1