【发布时间】:2017-08-18 04:04:47
【问题描述】:
当“位置:固定”属性应用于我的最左侧边栏列时,我的两个 Bootstrap 列向左移动时遇到问题。固定位置属性仅在此列到达窗口顶部时应用,否则此列是静态的。我正在使用 JQuery 执行此操作。在 JQuery 代码触发和应用固定位置属性之前,一切都已正确对齐。我在想,一旦将固定位置添加到我最左侧的侧边栏列中,就会出现“空白”,并且有问题的两列向左移动以填充它。
下面是我的代码,其中包含更多详细信息。如果我的解释不清楚,我深表歉意!
HTML:
#fixed1是页面滚动到浏览器窗口顶部后修复的最左侧边栏列。我在通过 JQuery 将#fixed1更改为固定位置后向左移动的两列旁边评论了“移动第 1 列”和“移动第 2 列”。
<div class="container-fluid">
<div class="row" id="places-container">
<!-- Begin Places Side Box -->
<div class="col-md-2" id="fixed1">
<p>Places</p>
<br>
<img src="images/places-logo.svg" id="sidebarLogo" class="center-block" style="width: 50px;">
<br>
<span id="places-text">
fill text fill text fill text fill text
</span>
</div>
<!-- End Places Side Box -->
<!-- Shifting Column 1 --> <!-- Begin Places Images -->
<div class="col-md-5">
<img src="images/places-img1.jpg" class="center-block">
</div>
<!-- Shifting Column 2 --> <div class="col-md-5">
<img src="images/places-img2.jpg" class="center-block">
</div>
<div class="col-md-10 col-md-offset-2">
<img src="images/places-img3.jpg" class="center-block">
</div>
<div class="col-md-10 col-md-offset-2">
<img src="images/places-img6.jpg" class="center-block">
</div>
<!-- End Places Images -->
</div>
</div>
CSS:
相当标准。这里没有发生太多事情。
#places-container {
font-size: 24px;
font-weight: bold;
}
#places-container img {
width: 100%;
padding-bottom: 25px;
}
JQuery:
var fixmeTop = $('#fixed1').offset().top;
$(window).scroll(function() {
var currentScroll = $(window).scrollTop();
if (currentScroll >= fixmeTop) {
$('#fixed1').css({
position: 'fixed',
top: '0',
left: '0'
});
} else {
$('#fixed1').css({
position: 'static',
});
}
});
以下是我制作的两张示例图片,以更好地说明我的问题。我确信这是一个非常简单的问题,我希望这可以帮助我更清楚地解决我的问题。
(明显错别字)
【问题讨论】:
标签: jquery html css twitter-bootstrap-3