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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:15:54+00:00 2026-05-29T18:15:54+00:00

Is it possible to determine which div is currently in the browser’s view, and

  • 0

Is it possible to determine which div is currently in the browser’s view, and then fire an event when that occurs? Basically, I have a website that has 5-6 sections all on one page and I want to fire events depending on which section is currently in view on the browser. I know we can link directly to positions of a page using the # tag in hrefs, but is this possible to determine which is currently in main view on the browser?

  • 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-29T18:15:56+00:00Added an answer on May 29, 2026 at 6:15 pm

    Yes, you can do that.
    The basic idea behind that is to watch the scrolling and to determine which of your sections is focused by the user.
    A good guess for this is usually the section, which is next to the top of your viewport:

    $(document).scroll(function() {
      var $this = $(this),
          scrollTop = $this.scrollTop(),
          // find the section next to the current scroll top
          sections = $(this).find('section'),
          topSection = null,
          minDist = Infinity;
    
      sections.each(function() {
        // calculate top and bottom offset of the section
        var top = $(this).offset().top,
            bottom = top + $(this).innerHeight(),
            // only use the minimum distance to the scroll top
            relativeDistance = Math.min(
              Math.abs(top - scrollTop), 
              Math.abs(bottom - scrollTop)
            );
        // in case the distance is smaller than
        // the previous one's replace it
        if (relativeDistance < minDist) {
          minDist = relativeDistance;
          topSection = this;
        }
      });
    
      // flip the 'top' class from current to now next one
      $('section.top').removeClass('top');
      $(topSection).addClass('top');    
    });
    

    You can see a quite nice example of this at the Play Webframework’s Homepage

    If that is not quite what you want, you may observe the full offset or position of any Element and compare it to the current viewport using $(window).innerWidth() or $(window).innerHeight()

    UPDATE
    Added a jsbin to see it in action. Enjoy 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to determine which submit button was used? I have a confirmation
In ASP.NET MVC, is it possible to define routes that can determine which controller
Possible Duplicate: jQuery: How to determine which <li> tag was clicked? I have a
Is it possible to determine which property of an ActiveX control is the default
Is it possible, with Javascript or some other technology to determine which hyperlink a
Is it possible to determine a specific file's fragmentation status (that is, the amount
Given an APK, is it possible to determine which version of Android platform it
Possible Duplicates: How to determine which html page element has focus? How do I
Is there a tool that can scan your code and determine which objects that
Using the Application.ThreadExceptionEventHandler, is it possible to determine which thread caused the exception (the

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.