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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:26:31+00:00 2026-05-26T20:26:31+00:00

This is a followup question for this: Scrollpane on the bottom, css is hacky,

  • 0

This is a followup question for this:
Scrollpane on the bottom, css is hacky, javascript is hard

I ended up doing the scrolling in the same way explained in the accepted answer.

Now there is a request that one item is selected somehow (eg. as an url parameter or by some javascript calls) I should scroll the pane to the item with the corresponding ID in the scrollpane. Like a link to an anchor () would work!

The supposed layout

I want to make a javascript call like this

function scrollTo(id) {
    $('#middle').magicallyScrollThatItemWouldBeVisible(itemid);
}

But this is not in jQuery (or at least I don’t know of it). So is there a way to make it?

I’ll post a simple jsFiddle here:
http://jsfiddle.net/ruisoftware/U6QdQ/4/

Help me write that scrollTo function!

A .animate would be fine too.

UPDATE: If it was not clear I would like it to only align to the left or right side of the panel, it it was overflowed on that side (so the minimum possible amount of scrolling happens)

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

    Since the elements have a fixed width, you can count the number of elements by using .index() + 1, and animate to this value (after subtracting the container’s width).

    If you want the element to be centered, use - Math.round(middle.width()/100)*50.

    Fiddle: http://jsfiddle.net/U6QdQ/17/

    //This code should be run on load / DOMReady
    (function($){ //Run on load / DOMReady
        $.fn.magicScrollTo = function(){
            var middle = $("#middle");
            var currentScrollLeft = middle.scrollLeft();
            var width = middle.width();
            var newScrollLeft = this.offset().left + currentScrollLeft - middle.offset().left;
            if(newScrollLeft >= currentScrollLeft && newScrollLeft <= currentScrollLeft + width - this.outerWidth()) return;
            if(newScrollLeft > currentScrollLeft){ //If the element is at the right side
                newScrollLeft = newScrollLeft - width + this.outerWidth();
            }
            middle.animate({
                scrollLeft: newScrollLeft,
            }, 'fast')
        }
    })(jQuery);
    

    Usage:

    //Select the 4rd element, and scroll to it (eq is zero-based):
    $('.item').eq(3).magicScrollTo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a followup question of How to encode characters from Oracle to Xml?
This is a followup question to my other widget-related question . I'd like to
This is a followup question to my other question : Run bat file in
This is a followup to this question . I seem to be stuck on
This is a followup on the question: ASP.NET next/previous buttons to display single row
This is a followup to a question I posted yesterday. I thought everything was
As kind of a followup to this question I've gotten a solution working on
THis is a followup to my previous question Font-dependent control positioning. It's an attempt
This is a followup to an earlier question ( Help Refining RegEx ("\b\d{6}([ ]{1,15})\d{7}\b")
This is a followup to my last question . I now have a byte[]

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.