Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 防止在滚动时粘贴的元素跳跃_Css_Twitter Bootstrap 3 - Fatal编程技术网

Css 防止在滚动时粘贴的元素跳跃

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;

我正在使用bootstrap的粘贴插件 HTML:

<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>