
I\'ve been trying to layout this page, but for the life of me, can\'t seem to get it to wor
I think this may work for you...
Working Example
JS:
$(window).scroll(function () { // on scroll
var win = $(window);
var title = $('.title');
var winWidth = $(window).innerWidth();
var titleWidth = title.width();
if (win.scrollLeft() >= titleWidth - winWidth) { // if scrolled to the right further than .title is wide minus the window's width
title.addClass('fixed'); // add the fixed class
title.offset({ //keep the title bar at the top
top: win.scrollTop(),
});
} else { // if not
title.removeClass('fixed'); // removed class fixed
title.offset({ // keep the title bar at the top anyway
top: win.scrollTop(),
});
}
});
CSS:
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
width: 1024px;
height:100%
}
.title {
background:red;
position: absolute;
z-index:2;
min-width: 100%;
}
#content {
background: blue;
padding-top:50px;
min-width:1024px;
min-height:100%;
}
.fixed {
position: fixed;
right: 0;
}
API documentation:
.scroll()
.innerWidth()
.width()
.scrollLeft()
.offset()
.addClass()
.removeClass()