简体   繁体   English

将div滚动到父div的顶部

[英]Stick div to top of parent div on scroll

This is a variation of the question of sticking a div to the top of the page. 这是将div粘贴到页面顶部的问题的变体。 Instead I need a div to stick to the top of its parent div, which has been set to overflow: auto . 相反,我需要一个div坚持其父div的顶部,该父div已被设置为overflow: auto

http://jsfiddle.net/7F22m/ (Code cobbled from here .) http://jsfiddle.net/7F22m/ (代码从这里拼凑而成。)

#sticky should stick to the top of #wrapper once it reaches the top of #wrapper . #sticky应该坚持的顶部#wrapper一旦它到达顶部#wrapper

They're multiple ways of making this work… A bit of guidance: http://jsfiddle.net/WykZ5/3/ 它们是使这项工作可行的多种方法……一些指导: http : //jsfiddle.net/WykZ5/3/

The code above isn't perfect but should be a start. 上面的代码并不完美,但应该是一个开始。 The reason it wasn't working is that the code didn't get launched. 它不起作用的原因是该代码未启动。

Do you use console.log() to debug? 您是否使用console.log()进行调试? If not Google it. 如果不是谷歌呢。 It will help a lot. 这会很有帮助。

Also check out: http://twitter.github.com/bootstrap/javascript.html#scrollspy 还要查看: http : //twitter.github.com/bootstrap/javascript.html#scrollspy

I used mostly used this code as reference: https://github.com/twitter/bootstrap/blob/master/docs/assets/js/application.js#L61 我主要使用此代码作为参考: https : //github.com/twitter/bootstrap/blob/master/docs/assets/js/application.js#L61

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM