cleanup timeouts for zooms

This commit is contained in:
Sanjay Bhangar 2018-03-14 23:21:14 +05:30
parent 9ee095b6db
commit 3fd440a849

View File

@ -60,7 +60,7 @@ function start(idx) {
function stop(idx) { function stop(idx) {
var data = slideData[idx] var data = slideData[idx]
console.log(current, data) console.log(current, data)
if (data.zoom_to) { if (data.zooms) {
reset_zoom(data) reset_zoom(data)
} else if (data.video && data.video.length) { } else if (data.video && data.video.length) {
reset_video(data) reset_video(data)
@ -121,8 +121,9 @@ window.addEventListener('blur', function(){
function reset_zoom(data) { function reset_zoom(data) {
data.zoomTimeouts.forEach(timeout => clearTimeout(timeout))
data.embed.postMessage('options', { data.embed.postMessage('options', {
'area': data.zoom_from 'area': data.zooms[0]
}) })
} }
@ -130,12 +131,13 @@ function start_zoom(data) {
// console.log('start zoon', Math.round(1000 * data.duration / 2)) // console.log('start zoon', Math.round(1000 * data.duration / 2))
for (var i=1; i<data.zooms.length; i++) { for (var i=1; i<data.zooms.length; i++) {
data.zoomTimeouts = [];
(function(j) { (function(j) {
setTimeout(function() { data.zoomTimeouts.push(setTimeout(function() {
data.embed.postMessage('options', { data.embed.postMessage('options', {
'area': data.zooms[j] 'area': data.zooms[j]
}) })
}, Math.round(1000 * (data.duration / data.zooms.length) * j)) }, Math.round(1000 * (data.duration / data.zooms.length) * j)))
})(i) })(i)
} }
} }