2

How would I create two scroll bars on div at top and bottom ?

I am working on web page. I have require content div as listing of candidate show candidate detail as all in rows columns. So I have require Div top scrolling bar on content.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
tailor
  • 366
  • 3
  • 6
  • 20
  • Do you mean for a single DIV, you want horizontal scrollbars at the top as well as the bottom? – techfoobar Mar 14 '14 at 09:23
  • The question and title as well are unclear. :) Edit: now it's clear:) – Mr.TK Mar 14 '14 at 09:25
  • 2
    The answer can be founded in this question: http://stackoverflow.com/questions/3934271/horizontal-scrollbar-on-top-and-bottom-of-table – Mr.TK Mar 14 '14 at 09:26
  • I am creating listing page in table format. I have require on top scrolling bar for listing page as horizontal and listing bottom horizontal scroll bar. – tailor Mar 14 '14 at 09:27

1 Answers1

5

Found this answer from SO itself : here.

Here is the fiddle of the answer.

HTML:

<div class="wmd-view-topscroll">
    <div class="scroll-div1">
    </div>
</div>
<div class="wmd-view">
    <div class="scroll-div2">
        @Html.Markdown(Model.Contents) @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  @Html.Markdown(Model.Contents)  
    </div>
</div>

SCRIPT:

$(function(){
    $(".wmd-view-topscroll").scroll(function(){
        $(".wmd-view")
            .scrollLeft($(".wmd-view-topscroll").scrollLeft());
    });
    $(".wmd-view").scroll(function(){
        $(".wmd-view-topscroll")
            .scrollLeft($(".wmd-view").scrollLeft());
    });
});

CSS:

.wmd-view-topscroll, .wmd-view {
    overflow-x: scroll;
    overflow-y: hidden;
    width: 300px;
    border: none 0px RED;
}

.wmd-view-topscroll { height: 20px; }
.wmd-view { height: 200px; }
.scroll-div1 { 
    width: 1000px; 
    overflow-x: scroll;
    overflow-y: hidden;
}
.scroll-div2 { 
    width: 1000px; 
    height:20px;
}
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
A J
  • 2,112
  • 15
  • 24
  • .wmd-view-topscroll scroll() calls .wmd-view scroll(), then .wmd-view scroll() calls .wmd-view-topscroll scroll(), then .wmd-view-topscroll scroll() calls .wmd-viewscroll() again, and then....hrm, is this not an infinite loop? – HoldOffHunger Jun 11 '19 at 23:19
  • @HoldOffHunger I don't see how, scrollLeft() as per jquery docs gets or sets the horizontal position of the element – chris c Oct 26 '20 at 21:51
  • Hey, chris c: I wrote a comment on infinite looping. You probably meant to direct that question to the poster, AJ? I didn't say anything about scrollLeft(). – HoldOffHunger Oct 26 '20 at 22:09
  • 1
    @chris c: Oh, btw, did you check that this creates an infinite loop? Check it out, it causes really buggy behavior, added a video gif to an answer here that gives a full explanation on how to do this: [horizontal scrollbar on top and bottom of table](https://stackoverflow.com/a/56384091/2430549) -- From 2010, 4 years before this question, far more popular, and looked over by far more eyes (i.e. better quality). Just a hint! – HoldOffHunger Oct 26 '20 at 22:21
  • @HoldOffHunger Nice work with that bug, I updated the code. But really it's not an infinite loop, as it ends once scrolling is stopped. More it just adjusts the scroll position of both elements when one is scrolled. Cheers :) – chris c Oct 27 '20 at 03:56