Browse Source

fix(sticky main menu): corrige le comportement en cas de resize; participe à #1

tags/v090
François Poulain 1 year ago
parent
commit
dd2187cd8e
2 changed files with 5 additions and 3 deletions
  1. +1
    -0
      .gitattributes
  2. +4
    -3
      assets/js/lib/sticky.js

+ 1
- 0
.gitattributes View File

@@ -2,4 +2,5 @@ biohdf/static/css/app.css.map -diff
biohdf/static/css/app.min.css -diff
biohdf/static/css/app.css -diff
biohdf/static/js/app.js -diff
biohdf/static/js/app.min.js -diff
biohdf/static/js/app.js.map -diff

+ 4
- 3
assets/js/lib/sticky.js View File

@@ -3,15 +3,16 @@ import $ from 'jquery';
$(() => {
const navbar = $('.mainmenu');
const sticky = navbar.offset().top;
let width = navbar.width();
let width = navbar.parent().width();

$(window).resize(() => {
width = navbar.width();
width = navbar.parent().width();
$(window).trigger('scroll');
});

$(window).scroll(() => {
if (window.pageYOffset >= sticky) {
navbar.css('width', `calc(${width}px + 2rem)`);
navbar.css('width', `${width}px`);
navbar.addClass('sticky');
} else {
navbar.removeClass('sticky');

Loading…
Cancel
Save