Fix Vantage Theme Menu Scroll Bug

There is a bug in the way the SiteOrigin's Vantage Theme handles its sticky menu.

In order to achieve the sticky menu effect, the theme checks if the user has scrolled down far enough, and if so creates a copy of the current menu bar and places it in a fixed position at the top of the page. The idea is that this copy will cover up the original menu bar and create the sticky menu effect. This works, but only to a point.

The Sticky Menu Bug

A problem occurs if the user has a sub-menu open while scrolling down. The sub-menu is not fully covered by the new sticky menu, so it can still be seen as it scrolls up the page. Furthermore, the sub-menu is actually set to be in front of the new sticky menu, giving the effect that it is the sticky menu's sub-menu which is being displayed and slowly disappearing off the top of the page instead of staying in place below the menu.

Fixing the Sticky Menu Bug

One way to fix this issue is to get rid of the copied menu entirely and then use some JavaScript to make the original menu itself become sticky when the user scrolls down. That way there is only one menu being displayed and no strange sub-menu effects occur.

First, we add some CSS to the theme to hide the copy, create a new class with the rules we need to make the menu sticky, and add a slight adjustment so it will work when the wordpress admin bar is showing:

.sticky { display:none; }
.sticky2 { position:fixed; top:0; z-index:1000; width:100%; } 
body.admin-bar .sticky2{ padding-top:32px; }

Then we need to trigger addition of the new sticky2 class to the menu at the right time (i.e. when the user scrolls down). We do this with the following JavaScript, which also does some adjusting of the positions of surrounding elements in order to make everything look right:

var elTop;
var $window = jQuery(window);
jQuery(document).ready(function($) {
   elTop = $('.main-navigation').offset().top;
   $window.scroll(function() {
		var nav = jQuery('.main-navigation');
		var adminoffset = (jQuery('body').hasClass('admin-bar'))?32:0;
		var issticky = ($window.scrollTop() > elTop - adminoffset);
		nav.toggleClass('sticky2', issticky);
		jQuery('#main-slider').css('margin-top', issticky?(nav.height()+adminoffset):0);


Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.