🎨 Style: add sub menu min-width equal to menu item (#97)

This commit is contained in:
Cell
2022-04-09 11:18:08 +08:00
parent 52f4527bf8
commit 87671ce72a
3 changed files with 13 additions and 9 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+11 -7
View File
@@ -76,14 +76,19 @@ class Theme {
initTwemoji() {
this.config.twemoji && twemoji.parse(document.body);
}
/**
* This is a dirty hack for fixing sub menu position error in desktop header
*/
initSubMenuDesktop() {
this.util.forEach(document.querySelectorAll('[has-children],.language'), ($item) => {
initMenu() {
this.initMenuDesktop();
this.initMenuMobile();
}
initMenuDesktop() {
// This is a dirty hack for fixing sub menu position error in desktop header
this.util.forEach(document.querySelectorAll('[has-children], #header-desktop .language'), ($item) => {
$item.addEventListener('mouseover', function(){
this.querySelector('.sub-menu').style.left= `${this.getBoundingClientRect().left}px`;
})
$item.querySelector('.sub-menu').style.minWidth= `${$item.offsetWidth - 8}px`;
});
}
@@ -925,8 +930,7 @@ class Theme {
try {
this.initSVGIcon();
this.initTwemoji();
this.initSubMenuDesktop();
this.initMenuMobile();
this.initMenu();
this.initSwitchTheme();
this.initSearch();
this.initDetails();