好吧,我想我已经得到了你想要的大部分东西。这对你来说足够了吗?
http://jsfiddle.net/wallysalami/T9k74/6/
HTML:
<body>
<div class='topbox'></div>
<table id='boxes-table'>
<tbody>
<tr>
<td>
<div id='leftbox' class='static-top-position'></div>
</td>
<td class='boxes-column'>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
<div class='box'></div>
</td>
</tr>
</tbody>
</table>
</body>
CSS:
body
{
text-align: center;
}
.fixed-top-position
{
position: fixed;
top: 10px;
}
.static-top-position
{
position: static;
}
.topbox
{
background-color: blue;
width: 998px;
height: 50px;
border: 1px solid grey;
margin: 13px;
display: inline-block;
text-align: left;
}
.box
{
height:300px;
width:228px;
border:1px solid grey;
display: inline-block;
background-color: orange;
margin: 5px;
}
#leftbox
{
height:300px;
width:200px;
border:1px solid red;
background-color: green;
margin: 10px 30px 0px 10px;
}
#boxes-table
{
max-width: 998px;
display: inline-block;
margin: auto 0px;
}
#boxes-table > tbody> tr > td
{
vertical-align: top;
width: auto;
}
Javascript(jQuery):
$(window).scroll( function() {
var tableTopPosition = $( '#boxes-table' ).offset( ).top - $( window ).scrollTop( );
var magicNumber = 5;
var leftbox = $( '#leftbox' );
var leftboxClass = leftbox.attr( 'class' );
var topPosition = leftbox.top;
if ( tableTopPosition < magicNumber && leftboxClass == 'static-top-position' )
{
leftbox.attr( 'class', 'fixed-top-position' );
} else if ( tableTopPosition > magicNumber && leftboxClass == 'fixed-top-position' )
{
leftbox.attr( 'class', 'static-top-position' );
}
});