首页 > 解决方案 > 依赖页面滚动的 iframe 内的粘滞按钮

问题描述

如何在 iframe 中制作粘性按钮?我的意思是,当您使用 position:sticky 或 -web-sticky 时,该按钮在页面滚动时似乎没有检测到它。

我怎么做这个?

标签: htmlcss

解决方案


当我想在 iframe 中使用粘性代码时,我总是使用Sticky-Kit使用这个我给出的链接点击这里

这很简单

只需在要卡在其父级中的元素上调用stick_in_parent。粘性元素“自下而上”,因此它们永远不会离开容器,不再担心粘性元素是否会意外覆盖您的页脚。

如果手动方式

<style>
div.sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    background-color: yellow;
    padding: 50px;
    font-size: 20px;
}
</style>

<div class="sticky">I will stick</div>

推荐阅读