【问题标题】:How to wait till adobe animation canvas drawn in iframe?如何等到在 iframe 中绘制 adobe 动画画布?
【发布时间】:2021-02-08 19:30:30
【问题描述】:

Adobe Animate Canvas 生成内容,我将该内容附加到 iframe 中。然后画布并在 iframes 文档中创建各种脚本变量。

我需要访问adobe动画的iframe完全加载时生成的变量'stage'。

我现在必须做的 - 附加 setTimeout 然后它似乎可以访问。 如果我不附加超时,控制台会抛出错误。

我想要实现的 - 我想避免 setTimeout 并以更好的方式重构代码。

我试过jquery:

$element.on( 'load', function() {
    // Gives error when accessing the stage property
    $element[0].contentWindow.stage
    // allows to access stage property
    setTimeout(() => {
        console.log($element[0].contentWindow.stage)
    }, 1000)
});

【问题讨论】:

  • 我不会抱怨投反对票,但至少您可以提供帖子缺少的信息。
  • 您实际上必须在 iframe 中执行此操作,然后在加载时告诉父级我完成了,继续!

标签: javascript jquery iframe createjs adobe-animate


【解决方案1】:

所以基本上我已经尝试了很多建议。

试过了:

$(element).load
$(element).on('load')
Other stuff...

对我有用的是这段代码:


    var onFullLoad = function(iframe) {
        return new Promise((resolve) => {
          var wait = function() {
            if (iframe && iframe.contentWindow && iframe.contentWindow.YourTargetedVariable) {
              resolve(iframe);
            } else {
              window.requestAnimationFrame(wait);
            }
          };
          wait();
        })
      };

那么你可以这样继续下去:

onFullLoad(yourTargetIframe).then(function(){
//your code
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-19
    • 2014-10-01
    • 2011-08-16
    • 2020-05-25
    • 2014-10-18
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    相关资源
    最近更新 更多