javascript - Horizontal scrolling with sticky div that stays on the left border -


i have 2 rows of data (green) , header (red), should visible @ times:

check out example have:

http://jsfiddle.net/j9c8r/33/

this current html:

<div class="main">     <div class="row">         <div class="sticky">sticky header a</div>         <div class="content">contenta</div>         <div class="content">contenta</div>         <div class="content">contenta</div>         <div class="content">contenta</div>     </div>     <div class="row">         <div class="sticky">sticky header b</div>         <div class="content">contentb</div>         <div class="content">contentb</div>         <div class="content">contentb</div>         <div class="content">contentb</div>     </div>     <div class="row">         <div class="sticky">sticky header c</div>         <div class="content">contentc</div>         <div class="content">contentc</div>         <div class="content">contentc</div>         <div class="content">contentc</div>     </div>     <div class="row">         <div class="sticky">sticky header d</div>         <div class="content">contentd</div>         <div class="content">contentd</div>         <div class="content">contentd</div>         <div class="content">contentd</div>     </div>     <div class="row">         <div class="sticky">sticky header e</div>         <div class="content">contente</div>         <div class="content">contente</div>         <div class="content">contente</div>         <div class="content">contente</div>     </div> </div> 

and css:

.main {     background-color:blue;     overflow:scroll;     height:200px;     width:400px; } .row {     height:50px;     overflow:scroll;     clear:both;     width:1000px;     background-color:yellow; } .sticky, .content {     float:left;     width:150px;     border:1px solid black; } .sticky {     background-color:red; } .content {     background-color:green; } 

now red header scrolls away content, should stick now, scroll vertically content (ms excel style).

how can achieved (preferably css).

update: important red headers scroll vertically along corresponding content stick left edge when scrolling horizontally.

i not think possible achieve goal through pure css items sticky use position:fixed unfortunately fixes them relative viewport.

with use of javascript (in case jquery library) , absolute positioning, should able achieve after:

new styles:

.row {     height:50px;     overflow:scroll;     clear:both;     width:1000px;     position:relative; //for absolute positioning of sticky     background-color:yellow;     padding-left:150px; //this size of sticky column doesn't cover content when left     box-sizing:border-box;//this padding doesn't add width 1000px }  .sticky {     background-color:red;     position:absolute; left:0; top:0; } 

javascript:

$('.main').scroll(function() {     $(this).find('.sticky').css('left', $(this).scrollleft()); }); 

http://jsfiddle.net/j9c8r/36/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -