我正在开发具有一些弹出窗口的插件。插件包含在某些页面(如iframe)中,但具有不同的域。除了添加此iframe之外,不允许在该页面上进行任何其他更改。
<iframe class="frame" style="width:100%" src="another-domain.com" frameborder="0" scrolling="no" height="4500px"></iframe>
请注意,scrolling =“ no”和height比页面的高度大得多。
弹出窗口出现时,弹出窗口应该在页面的垂直居中位置,而与用户向下滚动页面的数量无关。看照片
我尝试了$(top.window).scrollTop(),但是存在跨域问题。
有没有CSS技巧可以做到这一点?
先感谢您。
最佳答案
您可以尝试使用transform: translate()
函数CSS
iframe {
top: 50%;
position: absolute;
transform: translateY(-50%);
}
<iframe class="frame" style="width:100%" src="another-domain.com" frameborder="0" scrolling="no" height="4500px"></iframe>
关于javascript - 根据滚动条定位弹出iframe顶部窗口的顶部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38352437/