使用Bootstrap使div粘滞

时间:2022-11-25 15:09:24

I am using Bootstrap v3 for a div that I would like to make 'sticky' once scrolled from its current position, either moved to the left or left in position.

我正在使用Bootstrap v3作为div,一旦从当前位置滚动,我想使其变为“粘性”,无论是向左移动还是向左移动。

<div id="trigger1">
    <table class="nav-justified">
        <tr>
            <td>
                Menu Area
            </td>
            <td>
                <div class="text-right">
                    <div class="dropdown">
                        <a id="FilterDataLabel" class="btn btn-danger" data-target="#" data-toggle="dropdown" href="#" role="button">
                            <span aria-hidden="true" class="glyphicon glyphicon-filter">
                            </span>&nbsp;&nbsp;Filter Filter Menu
                        </a>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</div>

2 个解决方案

#1


1  

What you need is to use the CSS attribute position: fixed;

你需要的是使用CSS属性position:fixed;

Look this example: jsFiddle.

看看这个例子:jsFiddle。

#2


0  

It sounds like you want a div to be placed somewhere in your page and when the page is scrolled the div will stick to the top. If this is right, then you can use this... affix.

听起来你想要将div放在页面的某个位置,当页面滚动时,div会粘在顶部。如果这是正确的,那么你可以使用这个...词缀。

Here is a Fiddle with it doing this with a sticky div.

这是一个小提琴,用粘性div来做这件事。

Try this and use in what you are coding here.

试试这个并使用你在这里编码的内容。

<script>
$('.stick-top').affix({
  offset: {top: 50}
});
</script>

#1


1  

What you need is to use the CSS attribute position: fixed;

你需要的是使用CSS属性position:fixed;

Look this example: jsFiddle.

看看这个例子:jsFiddle。

#2


0  

It sounds like you want a div to be placed somewhere in your page and when the page is scrolled the div will stick to the top. If this is right, then you can use this... affix.

听起来你想要将div放在页面的某个位置,当页面滚动时,div会粘在顶部。如果这是正确的,那么你可以使用这个...词缀。

Here is a Fiddle with it doing this with a sticky div.

这是一个小提琴,用粘性div来做这件事。

Try this and use in what you are coding here.

试试这个并使用你在这里编码的内容。

<script>
$('.stick-top').affix({
  offset: {top: 50}
});
</script>