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

  • Home
  • SEARCH
  • 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 3406206
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:35:58+00:00 2026-05-18T05:35:58+00:00

I need the page to scroll just so that an element is visible. Options

  • 0

I need the page to scroll just so that an element is visible.

Options I’ve tried:

  • jQuery’s scrollTo: the problem is that the page scrolls so that the element is on top (or at least it tries to do that, much like how this works: <a name="xyz"> / <a href="#xyz">). I want the minimum amount of scrolling, so that the entire element is visible (and, if the element is too tall, work like the anchor there).

  • scrollIntoView: awful. I want it to scroll smoothly (like $.scrollTo($('#id1'), 'fast');). Also, it doesn’t seem to do what I want either.

  • 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-18T05:35:59+00:00Added an answer on May 18, 2026 at 5:35 am

    What you need to do is identify the position within the page of the element, top and bottom (and left/right if you are considering horizontal scrolling). Then identify the current position of the viewport on the window, the scrollTop of the window should then be animated to whatever value will bring the other just in to view.

    I just knocked up the following in this editor, so it’s untested, but will give you the general idea for a plugin.

    Updated – to show version that worked for the OP, as well as a smoother version

    jQuery.fn.scrollMinimal = function(smooth) {
      var cTop = this.offset().top;
      var cHeight = this.outerHeight(true);
      var windowTop = $(window).scrollTop();
      var visibleHeight = $(window).height();
    
      if (cTop < windowTop) {
        if (smooth) {
          $('body').animate({'scrollTop': cTop}, 'slow', 'swing');
        } else {
          $(window).scrollTop(cTop);
        }
      } else if (cTop + cHeight > windowTop + visibleHeight) {
        if (smooth) {
          $('body').animate({'scrollTop': cTop - visibleHeight + cHeight}, 'slow', 'swing');
        } else {
          $(window).scrollTop(cTop - visibleHeight + cHeight);
        }
      }
    };
    
    $('#item').scrollMinimal();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in an Iphone app, I am in need of building a page that scroll
I have any number of anchor links on a page that need to execute
I need to create a cherrypy main page that has a login area. I
I need a dropdown list on my page that will allow a user to
I need to find whether the web page is cached or not. That s
I have a page that has three divs one at the top, one at
I have the following scroll script, which scrolls round the page fine, works exactly
I have this page and if you look at the top right search...i need
I need to implement a scroll view which (on a button press) will page
In my base page I need to remove an item from the query string

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.