I am having trouble using this variable in two different functions. First, I calculate the offset needed from the top of the window for an element to be in view (the leavespace variable). Then, I have two different functions that need to utilize this, but I can't get it to work.
jQuery(document).ready(function($) {
$(function() {
var topbar_o_height = $(".ipro_topbar").outerHeight();
var nav_o_height = $(".nav").outerHeight();
if (topbar_o_height > 0) {
if ($('.nav').hasClass('menu-fixed-topbar')) {
var spacing = 10;
} else {
var spacing = 30;
}
} else {
var spacing = 10;
}
var extra_height = topbar_o_height + nav_o_height + spacing;
var leavespace = $(this.hash).offset().top - extra_height; // leave space for top menu
} // end function
$(".link_scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:leavespace}, 'slow');
});
if (document.location.href.indexOf('#') > -1 ) {
// will use the leavespace variable here too...
}
}); // End doc ready
var leavespace =usewindow.leavespace =jQuery(document).ready(function($) {. Currently it's out of scope which is why the other functions can't see it.scrollTop: leavespace + "px"