在iframe中相对于整个屏幕保持固定位置 [英] Keep fixed position inside an iframe relative to the whole screen

查看:559
本文介绍了在iframe中相对于整个屏幕保持固定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

  • 我们正在通过客户网站内的iframe来提供应用程序
  • iframe是无缝的,并且滚动仅在父div中进行.
  • 我们应用程序中的一个Divs位置固定,无论滚动多少,都应始终存在.
  • 更新:我们在iframe旁边部署了一个Javacript脚本,因此我们可以访问托管页面

问题:当在iframe中投放时,固定位置Div似乎没有相对于整个网页保持其固定位置.意思是,当有人滚动时,固定div不再真正保持固定.

The problem: When served inside the iframe, the fixed position Div doesn't seem to retain its fixed position relatively to the whole webpage. Meaning, when someone scrolls, the fixed div doesn't really stay fixed anymore.

有什么解决方法吗?

推荐答案

除非您也有权访问托管页面,否则您将无法做到这一点.

You can't do it unless you've got access to the hosting page as well.

考虑到您也可以控制托管页面,这是可能的,但并不是一件容易的事:/.

Given the fact you can control the hosting page too, it is sort of possible, but won't be easy or pretty :/.

必须通过托管页面上的fixed定位元素,现在我只能想到两个变化:

It has to be via a fixed positioned element on the hosting page and right now I can only think of two variations on top of that:

  1. 将固定元素放置在iframe之外.您可以在托管页面上创建脚本.
  2. 将iframe分为两个:一个包含要固定的元素(具有position: fixed样式),另一个包含其他所有元素.同样,您的脚本将创建两个iframe,而不是一个.
  1. Have the fixed element outside the iframe. Your script on the hosting page can create it.
  2. Divide your iframe to two: one with the element which you want fixed (with position: fixed style) and another with everything else. Again, your script will create two iframes instead of one.

这篇关于在iframe中相对于整个屏幕保持固定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆