-1

i’m struggling with some problems regarding a fixed menu item. I should mention that i’m still a beginner in javascript. Based on some answers that i found on this site, more specific here, i somewhat fixed the problem. Here is the code that i'm using:

`<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">    </script>
<script>
  function checkOffset() {
    var a=$(document).scrollTop()+window.innerHeight;
    var b=$('#footer').offset().top;
    if (a<b) {
      $('#menuC').css('bottom', '0px');
    } else {
      $('#menuC').css('bottom', (0+(a-b))+'px');
    }
  }
  $(document).ready(checkOffset);
  $(document).scroll(checkOffset);
</script>`  

Menu stops before the footer. The problem that i have now is that the menu item, depending on the height of the browser, is not always at the same spot. e.g. if the resolution is 1366 x 768 than the pixels above are almost ok, if the resolution is higher or lower than i need to change the numbers so that the menu stays where it should be.

Another answer that suits more my needs is this and based on that i made my own fiddle. Thats what i want my site to look like, only that i cant change the code to work for me since i dont understand the whole thing to make the necessary changes (for once, i don't understand why is there a need for the catcher divs or in js:

 `if(isScrolledTo(sticky)) {
  sticky.css('position','fixed');
  sticky.css('top','2px');` 

If sticky.css is the whole css file, this should change every items position to fixed ).

If someone could assist me solving this problem, I'd much appreciate it!

Community
  • 1
  • 1

1 Answers1

0

I think your missing () in your innerHeight jQuery function. For example :
var a=$(document).scrollTop()+window.innerHeight();

That's why it cannot detect the height of the window.

markvicencio
  • 146
  • 1
  • 7