需要 iFrame 在滚动页面的其他部分时不移动

need iFrame to not move when other part of page is scrolled

本文关键字:其他部 分时 移动 iFrame 滚动 需要      更新时间:2023-09-26

在我的 asp.net 应用程序中,我有一个带有标题的页面,然后在页面正文中显示一个人可以选择的项目。当有人选择一个项目时,iframe 会在正文的右侧出现,并显示有关所选项目的详细信息。iframe 大小和位置是使用屏幕大小设置的。在所有桌面浏览器中 - 我能够使用以下 javascript 解决此问题。

<script type="text/javascript">
window.onscroll = scroll;
</script>

这是JavaScript函数滚动

function scroll() {
    var divT = document.getElementById('searchframe');
    var divD = document.getElementById('detailframe');
    if (document.body.scrollTop > 80) {
        divT.style.top = document.body.scrollTop
        divD.style.top = document.body.scrollTop
        document.getElementById('detailframe').height = '100%';
    }
    if (document.body.scrollTop == 0) {
        divT.style.top = 75
        divD.style.top = 75
    }
}

在使用 http://code.google.com/p/ibbdemo2/- Adobe air ipad模拟器进行测试时,甚至没有调用滚动功能。我能够通过放置警报来判断这一点,警报会在所有其他浏览器甚至此模拟器中弹出,滚动功能除外。在其他浏览器中,将警报放在 window.onclick 行会显示警报,但在 safari 移动设备上不会显示警报 - 这意味着 window.onscroll 事件似乎甚至没有被触发。谢谢你的帮助。

编辑 - 我还可以在所有浏览器中使用以下任何行捕获滚动事件,移动野生动物园除外

window.onscroll = scroll;
document.onscroll = scroll;
document.addEventListener("scroll", scroll, false);

为什么你必须在javascript中这样做?

Css:

position:fixed;
right: 10px;
top: 10px;

不行?

此问题仅是由于模拟器引起的,实际上适用于设备。

document.getElementById('iframeID').style.top = intVal;