Scrolling In Child Div ( Fixed ) Should Scroll Parent Div
I have one parent and child div. Child div is absolutely positioned to the top and is scrollable. My requirement is to scroll the parent div when i scroll inside the child div and
Solution 1:
Listen for the scroll
event on the child. In the event handler function, set the parent's scroll top equal to the child's.
Something like the following:
$('#child').on('scroll', function(){
var sTop = $(this).scrollTop();
$('#parent').scrollTop(sTop);
});
Solution 2:
I did not quite do not fully understand the question, but there is a similar solution DEMO I hope this decision will help you
HTML
<!-- This acts as the overlay, or mask, of your content. --><divid="overlay"><divid="overlay-top"class="vert"></div><divid="overlay-bottom"class="vert"></div><divid="overlay-left"class="hor"></div><divid="overlay-right"class="hor"></div></div><!-- The entire content of your page would go here. --><divid="content"><h1>Top of content</h1><hr /><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. No vix everti corpora corrumpit, et mea exerci ponderum eloquentiam, vis an idque nominati. Ea mel errem conclusionemque, cu sea dicat omnesque. Facilis detracto reprehendunt mei ei.</p><p>Vim aperiam suscipit ne, et has euismod senserit, est ei ornatus mnesarchum. His delicata referrentur ad, vim an sapientem molestiae laboramus, ad quem clita consequuntur ius. Pro ei sint voluptatibus. Elaboraret definitionem per cu, liber deserunt interpretaris ad duo, cu vis petentium vulputate. His at vide patrioque, in labitur alterum sea.</p><p>Putent mentitum referrentur no usu. Ne autem eripuit delectus mei, forensibus persequeris vim eu, sint quaestio ad nec. Offendit aliquyam ius ex. Ex cum option noluisse. Repudiare suscipiantur est ut.</p><p>Ut vero scripta argumentum per, id nemore splendide appellantur vis. Et idque aliquam praesent nec. At wisi impetus deseruisse per, salutatus omittantur ex has. No sed accusata iudicabit, eu corrumpit deseruisse eos, et vis dictas suavitate. Ad quod abhorreant dissentias duo, ius ea quando eruditi nusquam.</p><p>Eos autem debet ut, vel ea omnium dolorum eligendi. Ex has magna assum iudico. Eu dictas hendrerit vis, animal dissentiunt mel cu. Cu usu nemore interesset temporibus. Mea ut adipisci praesent consequuntur, per et brute legimus commune. Pri eirmod dissentiunt ei.</p><p>In nonumy nostro invenire cum. Postea complectitur sit id. An saepe animal omittam usu, quem tantas id est, nam sint deleniti in. Dicit viderer reformidans ut quo. Mei ornatus molestie ut, id dolores vivendum menandri ius. Facer possim reformidans vix ut. Et utinam possim percipitur quo.</p><p>Nisl perpetua voluptaria vim et, cu per unum efficiendi, no labore instructior pri. In usu delenit intellegam, at delicata praesent eos. Cu civibus mentitum duo. Eu movet dolor vim, has cu senserit referrentur. An mel corpora comprehensam, constituto vituperata cum eu.</p><p>Ne vim nemore vidisse rationibus. Id partem percipit quaerendum mel. Soleat graecis placerat cu eum, sed at dolores recteque. In sit consul appetere, cum exerci legere accommodare ad. Cum at legimus patrioque neglegentur.</p><p>No alii aeque facilisis mea, his novum dissentias id. Ne his exerci feugait, mei te suas graeci iracundia. Ad paulo soluta vim, discere qualisque his eu. Ius ut fuisset offendit inciderint, mel putant impetus appellantur no. Sit ad integre officiis euripidis, libris necessitatibus at per. Tamquam insolens an duo, sed exerci electram ad, qui at doming inciderint adversarium.</p><p>Cum ex ornatus accusam, vocent dolorem definiebas sit et, ut illud takimata mei. Eos ex sale brute, bonorum mediocrem an nam. Ei alienum quaestio maiestatis has, iriure vivendo cu est, pri harum periculis ex. Per ad idque populo omnesque, novum reformidans definitionem eu nec. Mel reque evertitur voluptatum ea, inani iuvaret sententiae et has.</p><hr /><h1>Bottom of content</h1></div>
CSS
h1 {
font-weight: bold;
text-align: center;
}
p {
margin: 1em0;
}
#overlaydiv {
position: fixed;
width: 100%;
height: 100%;
background-color: gray;
}
/* The top and bottom "borders". */#overlay.vert {
height: 100px;
}
/* The left and right "borders". */#overlay.hor {
width: 100px;
}
/* Anchor the parts of your overlay boxes to the respective edges of the page. */#overlay-top { top: 0; }
#overlay-bottom { bottom: 0; }
#overlay-left { left: 0; }
#overlay-right { right: 0; }
/* Your content has padding equal to the sizes of your overlay "borders". */#content {
padding: 100px;
}
Post a Comment for "Scrolling In Child Div ( Fixed ) Should Scroll Parent Div"