Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 div 元素,当您滚动它时,我想将它与页面一起移动,如下图所示。但现在它只是坐在一个固定的位置。我怎样才能做到这一点?我知道我需要使用 JS,有人能指出我正确的方向吗?
<div id='slider'> </div>
不需要 JS 你应该使用 position fixed
div#slider { position: fixed; }
在没有 JavaScript 的情况下,您始终可以在 CSS 中使用固定定位。
#slider { position: fixed; top: 100px; left: 0px; }
#slider { position : fixed; }
我认为您正在寻找这种功能。在此处阅读有关如何使用的完整文档
<script type="text/javascript"> jQuery(document).ready(function($) ( { $('#floatdiv').addFloating( { targetRight: 10, targetTop: 10, snap: true }); }); </script>