A gravity forms support rep told me there was an issue with my javascript code but didn’t tell me what was wrong. I looked at the screenshot provided and say an error saying:
“Uncaught TypeError: Cannot read property ‘top’ of undefined”
Here’s the code that I’m using:
jQuery(function() {
// grab the initial top offset of the navigation
var sticky_navigation_offset_top = jQuery('#second-nav').offset().top;
// our function that decides weather the navigation bar should have "fixed" css position or not.
var sticky_navigation = function(){
var scroll_top = jQuery(window).scrollTop(); // our current vertical position from the top
// if we've scrolled more than the navigation, change its position to fixed to stick to top,
// otherwise change it back to relative
if (scroll_top > sticky_navigation_offset_top) {
jQuery('#second-nav').css({ 'left':0, 'position': 'fixed', 'top':0, 'width': '100%', 'z-index': 99999999 });
} else {
jQuery('#second-nav').css({ 'position': 'relative' });
}
};
// run our function on load
sticky_navigation();
// and run it again every time you scroll
jQuery(window).scroll(function() {
sticky_navigation();
});
});
I looked at some similar questions but I’m not a js fan 🙁
thanks for the help!
edit:
$(function() {
// grab the initial top offset of the navigation
var second-nav_offset_top = $('#second-nav').offset().top;
// our function that decides weather the navigation bar should have "fixed" css position or not.
var second-nav = function(){
var scroll_top = $(window).scrollTop(); // our current vertical position from the top
// if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
if (scroll_top > second-nav_offset_top) {
$('#second-nav').css({ 'position': 'fixed', 'top':0, 'left':0 });
} else {
$('#second-nav').css({ 'position': 'relative' });
}
};
// run our function on load
second-nav();
// and run it again every time you scroll
$(window).scroll(function() {
second-nav();
});
});'