首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用davidjbradshaw的iframe-resizer库

使用davidjbradshaw的iframe-resizer库
EN

Stack Overflow用户
提问于 2018-03-29 15:15:49
回答 1查看 1.7K关注 0票数 0

我是JavaScript新手,在使用iframe库时遇到了问题。

我有一个iFrame的角组件HTML文件,其中包含下面的代码。如您所见,我包含了iframeResizer.min.js文件,并且正在使用srcdoc动态构建iFrame的内容(我在这个框架的内容中包含了iframeResizer.contentWindow.min.js文件):

代码语言:javascript
复制
<script type='text/javascript' src='../iframeResizer.min.js'></script>

<iframe id="myIframe" srcdoc="<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<p>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?<p>On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.</p><script type='text/javascript' src='../iframeResizer.contentWindow.min.js'></script>" scrolling="no"></iframe>

<script>iFrameResize({log:true}, '#myIframe')</script>

我还为我的组件提供了一个scss文件,其中包含以下内容:

代码语言:javascript
复制
iframe {
    width: 1px;
    min-width: 100%;
}

我没有看到我的iFrame被调整大小,我也没有在控制台中看到任何iframe大小的日志。什么都没发生。知道为什么会发生这种事吗?我做错了什么?我是否需要一个角度指令来暴露必要的变量和行为--如果需要,你有这样的例子吗?很抱歉有菜鸟的问题,提前感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-29 16:30:47

FWIW,当我不得不在角度上做同样的事情时,我使用这里的方法创建一个指令来应用于iframes来添加一个负载处理程序:

https://stackoverflow.com/a/23948165/2079345

然后在负载处理程序中我做到了

代码语言:javascript
复制
        let $frame=$('#the-iframe');
        setInterval(function () {
            let height = parseInt($frame.contents().find('body').height());
            if (height !== oldHeight) {
                $frame.height(height + 30);
                oldHeight = height;
            }
        })

+ 30用于填充问题,您的用例可能有所不同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49559606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档