<div id="wrap">
<div class="section">
<div class="center">
<h3>Scroll</h3>
<div id="scroll">
<div class="scroll">
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled">
<span>We scrolling!</span>
</div>
<div class="scrolled" id="fixed">
<span>This is fixed!</span>
</div>
</div>
</div>
</div>
</div>
</div>
html,
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 16px;
line-height: 1.4;
color: #555;
background: #fff;
}
* {
box-sizing: border-box;
}
#wrap {
position: relative;
}
.section {
padding: 40px 20px;
border-bottom: 1px solid #ddd;
&:last-child {
border-bottom: 0;
}
}
.center {
width: 100%;
max-width: 980px;
margin: auto;
}
h3 {
margin: 0 0 32px;
font-size: 24px;
}
#scroll {
width: 280px;
height: 280px;
margin: auto;
box-shadow: 0 0 0 1px #aaa;
position: relative;
}
.mCSB_inside > .mCSB_container {
margin-right: 0;
}
.scroll {
width: 100%;
height: 100%;
}
.scrolled {
padding: 10px;
text-align: center;
&#fixed {
background: #777;
color: #fff;
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
}
}
View Compiled
$(function () {
function treatScroller($scrolledContainer, $fixedItem) {
$scrolledContainer.css({
paddingBottom: $fixedItem.innerHeight()
});
}
function treatFixed($fixedItem, $container, $scrolledContainer, top) {
var fixedItemHeight = $fixedItem.innerHeight(),
containerHeight = $container.height()
$fixedItem.css({
top: containerHeight - top,
marginTop: fixedItemHeight * -1
});
}
$('.scroll').mCustomScrollbar({
theme: 'dark',
scrollInertia: 200,
callbacks: {
onInit: function () {
treatScroller($('#' + this.mcs.content.attr('id')), $('#fixed'));
treatFixed($('#fixed'), $(this), $('#' + this.mcs.content.attr('id')), this.mcs.top);
},
whileScrolling: function () {
treatScroller($('#' + this.mcs.content.attr('id')), $('#fixed'));
treatFixed($('#fixed'), $(this), $('#' + this.mcs.content.attr('id')), this.mcs.top);
}
}
});
});