Reputation: 16281
I have designed a Bootstrap two column layout col-md-6
. A row with a panel on top with a table
, a left column panel
with a list of media
items, and a right column with a panel hat contains text.
The contents are in a container-fluid
layout. When scrolling the page, while the left panel <ul/>
list can scrolls down, the right column panel will disappear from the view.
I want to keep this panel-text
stuck to the viewable area below the panel-summary
.
I have applied a fixed
position with a translateY(0px);
transform to the row containing that panel:
.row-floating {
position: fixed;
margin-top: 0px;
top: 60px;
transform: translateY(0px);
}
The problem is that, while scrolling the panel-text
will overrides the panel-summary
anyways, while it should stay stuck below this panel:
JSFiddle here.
The solution proposed works, so I have updated the Fiddler here adding
a webkit-transform
to avoid possible flickering while Y-scrolling:
.row-floating {
transform: translateZ(0);
-webkit-transform: translateZ(0);
}
a offset from top to keep the panel at bottom of the navbar
(+44px):
$('.panel-floating').css('position', 'fixed').css('top', 44.0).css('width',actualWidth);
Upvotes: 1
Views: 7342
Reputation: 12176
What you are looking for can't be done in css alone you have to use JS. Since you are using bootstrap. I am including jquery
$(document).ready(function(){
var offsetTop = $('.row-floating').offset().top;
var actualWidth =$('.row-floating').width();
$(window).scroll(function() {
if( window.pageYOffset >= offsetTop){
$('.row-floating').css('position', 'fixed').css('top', 0).css('width',actualWidth);
} else {
$('.row-floating').css('position', 'relative').css('top', 'auto').css('width','auto');
}
});
});
Fiddle for the same https://jsfiddle.net/karthick6891/5je5d18g/5/
Upvotes: 3