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 3596822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:02:19+00:00 2026-05-18T20:02:19+00:00

I have a html table with scrollbar (i.e. overflow is set). When I scroll

  • 0

I have a html table with scrollbar (i.e. overflow is set). When I scroll the table, I would like to get the the current top-row in position (i.e. according to user-view of table).

How would I do this?

Can anyone of you help me with an example?

  • 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-18T20:02:19+00:00Added an answer on May 18, 2026 at 8:02 pm

    Here is something that might help get you started if you’re going at it with vanilla JavaScript. It’s definitely not perfect but might spark some ideas… JSFiddle Example

    [update] code from link above

    JavaScript

    document.getElementById('btn').onclick = function() {
        var tbl = document.getElementById('tbl');
        var scrollAmt = document.getElementById('asdf').scrollTop;
        var totalRowHeight = 0,
            viewTolerance = 1/3, //if only 1/3 of row is showing highlight next row
            rowHeight;
    
        for( var i = 0; i < tbl.rows.length; i++ ) {
            totalRowHeight += rowHeight = tbl.rows[i].offsetHeight;
            if( totalRowHeight > scrollAmt ) {
                //if row doesn't meet viewTolerance requirement highlight next row
                var rowIndex = (totalRowHeight - scrollAmt < rowHeight*viewTolerance) ? i + 1: i;
                tbl.rows[rowIndex].style.backgroundColor = '#ff00ff';
                break;
            }
        }
    }
    

    HTML

    <div id="asdf">
        <table id="tbl">
            <tbody>
                <tr><td>asdf</td><td>asdf1</td></tr>
                <tr><td>asdf</td><td>asdf2</td></tr>
                <tr><td>asdf</td><td>asdf3</td></tr>
                <tr><td>asdf</td><td>asdf4</td></tr>
                <tr><td>asdf</td><td>asdf5</td></tr>
                <tr><td>asdf</td><td>asdf6</td></tr>
                <tr><td>asdf</td><td>asdf7</td></tr>
                <tr><td>asdf</td><td>asdf8</td></tr>
            </tbody>
        </table>
    </div>
    <input type="button" value="getTop()" id="btn" />
    

    CSS

    #asdf{
        height:100px;
        overflow:scroll;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html table with scrollbar (i.e. overflow is set). When I scroll
The following is a 3 x 3 table: <html> <body style=overflow:hidden;> <style> div.table_div {overflow:scroll;width:378px;height:117px;position:relative;}
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2
I have a HTML table like this: <table border=1> <tbody> <tr> <td><a href=# class=delete>DELETE
I have a HTML table like this: <table border=1> <tbody> <tr> <td><a href=# class=delete>DELETE
I have HTML Like Below. I have a table inside another table.Each TD in
I have a html table and I want to freeze the header row th
I have the following piece of HTML that creates a table with a scrollbar
I have HTML table with 10 rows and which has a Current Value column
i have html table and add in table row in runtime. i want to

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.