在创建一个网站时,我发现浏览别人的网站可以更容易地想象我想要做的事情。我找到了一个网站,它的浏览器窗口的设置方式允许在屏幕上同时出现单独的“窗口”。因此,如果您滚动屏幕的一部分,其余的屏幕将不会这样做,只有部分您滚动。同样地,当您滚动整个屏幕时,有些元素不会与它一起滚动,相反,它们似乎是固定不变的。
我正在寻找的是在我的站点中实现这一点的一种方法--类似于以下“示例”:
[...]
<window position="some-number" size="some-number">
<!-- not a real element -->
[...]
</window>
[...]有什么一般的方法吗?你必须在JavaScript中对这种行为进行编程吗?
发布于 2020-07-22 18:31:23
当您滚动元素时,元素留在它们的位置的一种方法是使用position: fixed CSS语句。看这个例子。
#notscrolling {
position: fixed;
left: 200px;
top: 10px;
}<div id="scrolling">
<p>
This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will
scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>This will scroll<br>
</p>
</div>
<div id="notscrolling">
<p>this will not scroll</p>
</div>如您所见,最左边的p滚动,但最右边的p没有。
发布于 2020-07-22 18:11:57
这可以通过css样式来实现,比如:将它固定/粘贴到您不想滚动的html元素。
最好的解决方案是使用React,因为React帮助我们创建您自己的自定义组件,这样您就可以像定义上面的用法那样轻松地创建和使用它。
https://stackoverflow.com/questions/63040467
复制相似问题