From e3648a21a977726f8a3be3f4b06d9025f845f9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kantoj=C3=A4rvi?= Date: Mon, 23 Jul 2018 16:27:47 +0300 Subject: [PATCH] Ensure course menu width when fixed --- assets/js/aplus.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/assets/js/aplus.js b/assets/js/aplus.js index 4059afb53..67b796b49 100644 --- a/assets/js/aplus.js +++ b/assets/js/aplus.js @@ -45,23 +45,30 @@ $(function() { var modifyMenu = function() { var menu = $('#main-course-menu'); - if ($(window).scrollTop() > menuHeight && !menuFixed) { + if (!menuFixed && $(window).scrollTop() > menuHeight) { + var w = menu.width(); menu.addClass('fixed'); + menu.css('width', ""+w+"px"); menuFixed = true; - } else if ($(window).scrollTop() < 50 && menuFixed) { + } else if (menuFixed && $(window).scrollTop() < 50) { menu.removeClass('fixed'); + menu.css('width', ''); menuFixed = false; } }; - $(window).bind('scroll', function () { - modifyMenu(); - }); - - $(window).bind('resize', function () { - modifyMenu(); - }); + var updateMenu = function() { + var menu = $('#main-course-menu'); + if (menuFixed) { + menu.removeClass('fixed'); + menu.css('width', ''); + menuFixed = false; + modifyMenu(); + } + }; + $(window).bind('scroll', modifyMenu); + $(window).bind('resize', updateMenu); }); /**