Css 防止在滚动时粘贴的元素跳跃
我正在使用bootstrap的粘贴插件 HTML:Css 防止在滚动时粘贴的元素跳跃,css,twitter-bootstrap-3,Css,Twitter Bootstrap 3,我正在使用bootstrap的粘贴插件 HTML: <html> <head> ... <style> h1 { width: 100px; height: 100px; background: green; margin: 0; top: 10px; } h1.affix { top: 8px;
<html>
<head>
...
<style>
h1 {
width: 100px;
height: 100px;
background: green;
margin: 0;
top: 10px;
}
h1.affix {
top: 8px;
}
body {
padding: 10px;
height: 5000px;
}
</style>
</head>
<body>
<h1 data-spy="affix" data-offset-top="10">yo!</h1>
</body>
</html>
如何修复此问题?尝试以下方法:
使用粘贴类
<h1 class="affix">yo!</h1>
哟!
现在它不会跳了 这样它就不会跳转了,因为它马上就被固定了,我的代码是静态定位的。h1
。我可以知道为什么你的h1
是静态定位的。因为我希望它在滚动时随内容移动,并且只有在到达顶部时才粘到顶部。这个例子在顶部已经有了h1
,但在生产中不会是100%的代表性
<h1 class="affix">yo!</h1>