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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:47:53+00:00 2026-05-28T01:47:53+00:00

I’m trying to do the next thing with jQuery. I want that when you

  • 0

I’m trying to do the next thing with jQuery. I want that when you move throw the <h2 /> headings that higlight the right menu. My code is next to the images. Actually I only have the functionality that moves the menu and that when you click is moved and highlighted. I need do the same but with only moving the scrollbar.

Actual example working: http://jsfiddle.net/fAcTX/1/

enter image description here


enter image description here


enter image description here

    <div id="floating-divs">
        <div id="box-sidebar-menu" class="abt-ptn-sidebar-widget box-sidebar-menu-float">
            <ul>
                <li class="active"><a href="#header1">Peter Saville</a></li>
                <li><a href="#header2">About Saville Consulting</a></li>
                <li><a href="#header3">Clients</a></li>
            </ul>
        </div>
    </div>

<script>
    (function($) {
        $.fn.floatmenu = function(options) {
            // merges the given options with some default options
            var options = $.extend({
                topPadding: 10
            }, options);

            return this.each(function() {
                // fetches and initializes the current element.
                var obj = $(this);

                var position = $(obj).offset(),
                cssPosition = $(obj).css('position');

                // tests if a "position" was set on the element, if not, sets a default
                if(cssPosition == '') {
                    cssPosition = 'static';
                }

                // attaches an event to listen for scroll events
                $(window).scroll(function(e) {
                    // if the window's inner frame passes the top of the element,
                    // start moving the menu
                    if($(window).scrollTop() > (position.top - Number(options.topPadding))) {
                        $(obj).
                            css('position','fixed').
                            css('top', options.topPadding);
                    }
                    // the window's inner frame has not passed the menu, reset
                    // the objects position
                    else {
                        $(obj).css('position', cssPosition);
                    }
                });
            });
        };
    })(jQuery);

    $(document).ready(function(){
        $("#floating-divs").floatmenu();

        $("#box-sidebar-menu li a").click(function(){
            $("#box-sidebar-menu li").removeClass("active");
            $(this).parent().addClass("active");
        });
    });
</script>
  • 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-28T01:47:54+00:00Added an answer on May 28, 2026 at 1:47 am

    Here is a working example.
    link

    I have changed the plugin a bit, in case you need to ushe or add some methods (ex. ‘update’). This plugin initializes with the initial top positions of every . They are pushed in the array elemPos, and than sent to the plugin. The main check of conditions is in this part(you have to modify it, it doesn’t have all the possible cases in this if condition):

                    var localEl= 0;
                    $.each(positionsTop , function(index, value) {
                        if (winTop > value) {
                            localEl= index;
                        }
                    });
    
                    if (currentEl != localEl) {
                        currentEl = localEl;
                        $('li.active', elem).toggleClass('active');
                        $($('li', elem)[currentEl]).toggleClass('active');
                    }
    

    Here is the whole plugin:

       (function($) {
    var defaults = {
        topPadding: 10,
        posTops: [10, 20]
    };
    var options;
    var currentEl = -1;
    var methods = {
        init: function() {
    
            return this.each(function(elem) {
    
                // fetches and initializes the current element.
                var obj = $(this);
    
                var position = $(obj).offset(),
                    cssPosition = $(obj).css('position');
    
                // tests if a "position" was set on the element, if not, sets a default
                if (cssPosition == '') {
                    cssPosition = 'static';
                }
                var positionsTop = options.posTops;
                //reset counter
                $('a', elem).click(function(alink) {
                    var parentUL = $('#floating-divs ul');
                    currentEl = $(this).parent().index();
    
                    // window.scrollBy(0,positionsTop[currentEl]);
                    $(window).scrollTop(positionsTop[currentEl]);
                });
    
    
                // attaches an event to listen for scroll events
                $(window).scroll(function(e) {
                    // if the window's inner frame passes the top of the element,
                    // start moving the menu
                    var winTop = $(window).scrollTop();
                    if (winTop > (position.top - Number(options.topPadding))) {
                        $(obj).
                        css('position', 'fixed').
                        css('top', options.topPadding);
    
                        var localEl = 0;
                        $.each(positionsTop, function(index, value) {
                            if (winTop > value) {
                                localEl = index;
                            }
                        });
    
                        if (currentEl != localEl) {
                            currentEl = localEl;
                            $('li.active', elem).toggleClass('active');
                            $($('li', elem)[currentEl]).toggleClass('active');
                        }
                    }
                    //else
                    //ADD CODE HERE FOR OTHER SCROLL POSITIONS
                    // the window's inner frame has not passed the menu, reset
                    // the objects position
                    else {
                        $(obj).css('position', cssPosition);
                    }
                });
            });
    
        },
        update: function(args) {
            alert(args);
        }
    };
    
    $.fn.floatmenu = function(arguments, method) {
    
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
    
            options = $.extend(defaults, arguments);
            return methods.init.call(this, options);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }
    
    };
    
    })(jQuery);
    

    This is very important part. You have to initialize the plugin with all the top positions of the divs:

        var elemPos = new Array();
    
        $('#example_1 div').each(function() {
            var pos = $(this).offset();
            elemPos.push(pos.top);
        });
    
        $("#floating-divs").floatmenu({
            topPadding: 10,
            posTops: elemPos
        });
    

    Selection relative to position example

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.