August 30th, 2013, 08:13 AM
-
Fixed menu stoping at footer
Dear dev shed community, i’m struggling with some problems regarding a fixed menu item. I should mention that i’m still a beginner in javascript. I’ve searched the web and found this code on how to stop a fixed menu item for overlapping with the footer :
Code:
<script src="(URL address blocked: See forum rules)"></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>
and it’s working. Menu stops before the footer. The problems that i have now are:
1) 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. Should i change something on that code to make it compatible for all resolutions or should i put a complete different code that fits my needs best ?
2) i added this code to one php file where the particular menu item is (just to experiment) but i want it to be everywhere else where the same menu is in use and it seems kinda troublesome to copy-paste it to each php file since there are a lot of them. Is there a way for example to include this code in the css where all the properties for the menu are or something along those lines so that i only have to write it once ?
Sorry for the long post and please be patient with me.
Thanks in advance leftycool
August 30th, 2013, 01:15 PM
-
To answer your second question, if you drop your javascript code into its own file with the extension .js, you can add a <script src="/path/to/that/file.js"></script> tag to your web page(s) without having to copy and paste the code itself.
August 30th, 2013, 02:17 PM
-
Thank you. So there is no solution to avoid editing all the php files :-(.
Anyhow i'll try your recommendation.
August 30th, 2013, 02:27 PM
-
I wouldn't say there is no solution. You can implement any templating system, where your site's theme, including the <head> and all your scripts and whatnot, are contained in a single code snippet that's applied to all your site's pages.
August 30th, 2013, 02:41 PM
-
This sounds like more work (not to mention that i have to learn first how to do it) than copying and pasting a few lines in ~30 files 
Well with no solution i meant no easy solution that a beginner like me could do.