Mootools - How to contain a menu sidebar between header and footer

Why?
This has taken me too long to figure out and I hope I don't lose this note again. The only website that was titled similarly kept slowing down my computer too much so I decided to work out my own. The complexity is due to content also being dynamically resized in height.

What?
Basically I have a menu in a sidebar, I don't want it to overlap the header nor the footer.I have a content page next to it which changes in height dynamically (a separate mootool function to this one).

How?
So this is my take on it, if anyone has a better idea, I'd really appreciate it.
copyraw
window.addEvent('scroll', function() {

    var menu_highest_top = $('jdo_marker_table').getCoordinates().top;
    var menu_height = $('jdo_actions').getCoordinates().height;
    var component_top = $('jdo_overall').getCoordinates().top;
    var component_height = $('jdo_overall').getCoordinates().height;
	var match_lowest_y = component_height + component_top - menu_height;
	var match_highest_y = menu_highest_top + (component_top - menu_highest_top);

	if( window.XMLHttpRequest ) {
		if (document.documentElement.scrollTop > menu_highest_top || self.pageYOffset > menu_highest_top) {
			if (document.documentElement.scrollTop > match_lowest_y || self.pageYOffset > match_lowest_y) {
				$('jdo_actions').style.position = 'absolute';
				$('jdo_actions').style.top = match_lowest_y + 'px';
			} else {
				$('jdo_actions').style.position = 'fixed';
				$('jdo_actions').style.top = '5px';
			}
		} else {
			$('jdo_actions').style.position = 'relative';
			$('jdo_actions').style.top = '0px';
		}
	}
});
// still to do: smoothscroll? if already overlaps then flicks up
  1.  window.addEvent('scroll', function() { 
  2.   
  3.      var menu_highest_top = $('jdo_marker_table').getCoordinates().top; 
  4.      var menu_height = $('jdo_actions').getCoordinates().height; 
  5.      var component_top = $('jdo_overall').getCoordinates().top; 
  6.      var component_height = $('jdo_overall').getCoordinates().height; 
  7.      var match_lowest_y = component_height + component_top - menu_height; 
  8.      var match_highest_y = menu_highest_top + (component_top - menu_highest_top)
  9.   
  10.      if( window.XMLHttpRequest ) { 
  11.          if (document.documentElement.scrollTop > menu_highest_top || self.pageYOffset > menu_highest_top) { 
  12.              if (document.documentElement.scrollTop > match_lowest_y || self.pageYOffset > match_lowest_y) { 
  13.                  $('jdo_actions').style.position = 'absolute'
  14.                  $('jdo_actions').style.top = match_lowest_y + 'px'
  15.              } else { 
  16.                  $('jdo_actions').style.position = 'fixed'
  17.                  $('jdo_actions').style.top = '5px'
  18.              } 
  19.          } else { 
  20.              $('jdo_actions').style.position = 'relative'
  21.              $('jdo_actions').style.top = '0px'
  22.          } 
  23.      } 
  24.  })
  25.  // still to do: smoothscroll? if already overlaps then flicks up 
Category: MooTools Framework :: Article: 426

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.