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/



<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>
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):
Here is the whole plugin:
This is very important part. You have to initialize the plugin with all the top positions of the divs:
Selection relative to position example