Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:03:40+00:00 2026-05-30T08:03:40+00:00

Context I have a div with overflow: auto property. In this div , I

  • 0

Context

I have a div with overflow: auto property.

In this div, I have this:

<h3>Category 1</h3>
<ul>
    <li>blabla</li>
    <li>blabla</li>
    etc...
</ul>
<h3>Category 2</h3>
<ul>
    <li>blabla</li>
    <li>blabla</li>
    etc...
</ul>
<h3>Category 3</h3>
    etc...

I would like when I scroll, the current category attaches the top of the div, until the next category. When I arrive at an other category, it attaches the top in place of the previous.

Difficult to explain, so I made an image:

enter image description here

I’m sure I saw this in a website, but I don’t remember.

Questions

  • Do you know a plugin for this or a site with this?
  • Can you give me some tracks to develop it?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:03:41+00:00Added an answer on May 30, 2026 at 8:03 am

    JSFiddle Demo – http://jsfiddle.net/h2p6W/3/

    Attach an event listener to your scrollable div and measure the headers’ positions in the div. Then pick the one that is the small negative value and display it’s text to your header.

    $('#scroller').scroll(function () {
        var positions = $('h3', this).map(function() {
                return {
                    top: $(this).position().top,
                    el: this
                };
            }).get();
    
        //Go backwards through the array and pick the first negative (smallest) value
        for(var i = positions.length - 1; i >= 0; i--) {
            if(positions[i].top < 0) {
               $('#header').text($(positions[i].el).text());
               return;
            }
        }
    });
    

    For instance, if you have 5 headers in your scrollable div, and the positions are:

    [-100, -50, -20, 30, 120] – Then the -20 is the header you want to display.

    EDIT – refactored code

    JSFiddle Demo – http://jsfiddle.net/h2p6W/4/

    $('#scroller').scroll(function () {
        var category = '';
    
        $($('h3', this).get().reverse()).each(function () {
            if($(this).position().top < 0) {
                category = $(this).text();
                return false;
            }
        });
    
       $('#header').text(category);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a div whose css looks like this: .class { overflow:auto; resize:
I have an absolutely positioned DIV with overflow auto. When I scroll down, the
So I have this <div /> with overflow: auto . Inside of it are
I have an IE8 buggy horizontal scrollbar problem, similar to this: DIV with overflow:auto
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I have a div, it has overflow:auto and I have content that has a
I have a div with the content set for overflow: auto and height: 300px
i have a div with height:100px and overflow:auto the content is dynamic. i want
I basically have a layout like this: <body> <div style=height: 150px; width: 200px; background:
I have a relatively -positioned div, which has overflow: auto set. Inside that, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.