24 lignes
522 B
JavaScript
24 lignes
522 B
JavaScript
import $ from 'jquery';
|
|
|
|
$(() => {
|
|
const navbar = $('.mainmenu');
|
|
const sticky = navbar.offset().top;
|
|
let width = navbar.parent().width();
|
|
|
|
$(window).resize(() => {
|
|
width = navbar.parent().width();
|
|
$(window).trigger('scroll');
|
|
});
|
|
|
|
$(window).scroll(() => {
|
|
if (window.pageYOffset >= sticky) {
|
|
navbar.css('width', `${width}px`);
|
|
navbar.addClass('sticky');
|
|
} else {
|
|
navbar.removeClass('sticky');
|
|
navbar.css('width', '100%');
|
|
}
|
|
});
|
|
$(window).trigger('scroll');
|
|
});
|