Menu Active problem

Menu Active problem

Hi there

I'm testing a jQuery script (see below). What it does is that it highlights in the menu which part of the webpage you are currently on. Basically, no problem using it.

  1. var topMenu = jQuery("#nav ul"),
  2. topMenuHeight = topMenu.outerHeight() + 15,
  3. menuItems = topMenu.find("a"),
  4. scrollItems = menuItems.map(function () {
  5. var item = jQuery(jQuery(this).attr("href"));
  6. if (item.length) return item
  7. });

  8. jQuery(window).scroll(function () {
  9. var fromBottom = jQuery(this).scrollBottom() + topMenuHeight;
  10. var cur = scrollItems.map(function () {
  11. if (jQuery(this).offset().bottom < fromTop) return this
  12. });
  13. cur = cur[cur.length - 1];
  14. var id = cur && cur.length ? cur[0].id : "";
  15. menuItems.parent().removeClass("active").end().filter("[href=#" + id + "]").parent().addClass("active")
  16. });

But when I make the website scroll to bottom of the page on load (see below), the script doesn't seem to work.

  1. <body onload="window.location.hash = 'home'">
Any ideas? Thank you very much!