gpt4 book ai didi

javascript - jQuery:在页面中心保留一个div,即使页面向下滚动

转载 作者:行者123 更新时间:2023-11-28 03:58:01 24 4
gpt4 key购买 nike

我想让一个 div 在屏幕上居中,这样当页面向下/向上滚动时,div 会平滑地滚动到页面的中心。我正在尝试 this code (please see jsfiddle),但不起作用。有人可以帮我吗?谢谢。

最佳答案

你不需要jquery,只需使用css

HTML

<div id="senad">content</div>

CSS

 #senad { width: 200px; height: 200px; position: fixed; top: 50%; left: 50%; border: 1px solid gray;}

这将使元素居中。

关于javascript - jQuery:在页面中心保留一个div,即使页面向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7209732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com