我有这个菜单(这也发生在网站文本中)
<div id="container" class='container'>
<div class='meta-background'></div>
<section class='meta-container'>
<div class="meta-menu meta-menu-top">
<ul>
<li>testsas</li>
<li>fdadasdasdas</li>
<li>dsdasdsadasdsa</li>
</ul>
<span class="meta-title">WEBSITE</span>
</div>
<div class="meta-menu meta-menu-bottom"></div>
</section>
</div>
的CSS:
/* contaner */
/* * { padding:0; margin:0; box-sizing: border-box;} */
.container {
max-width: 2380px;
margin-left: auto;
margin-right: auto;
}
.meta-container {
display: flex;
/* -webkit-box-pack: center; */
/* -ms-flex-pack: center; */
justify-content: center;
}
.meta-background {
position: fixed;
margin-left: auto;
margin-right: auto;
z-index: -1;
background-size: cover;
background-repeat: no-repeat;
-webkit-filter: blur(10px);
filter: blur(10px);
top: 0;
right: 0;
bottom: 0;
left: 0;
/* background-image: url('./assets/img/3.jpg'); */
}
.meta-title {
color: white;
position: absolute;
bottom: 10px;
display: block;
}
/* menus */
.meta-menu-top {
background: #252422;
color: #959595;
border-radius: 0px 0px 10px 10px;
/* top: 0px; */
position: absolute;
height: 48%;
width: 360px;
opacity: 0.7;
display: flex;
justify-content: center;
}
.meta-menu-top ul {
padding: 0;
margin-top: 30%;
}
.meta-menu-top li {
list-style-type: none;
display: block;
}
.meta-menu-bottom {
background: #eef1f5;
color: white;
border-radius: 10px 10px 0px 0px;
/* bottom: 0px; */
position: absolute;
height: 48%;
width: 360px;
}
和JS隐藏/显示菜单
let menutop = $('.meta-menu-top'),
menubottom = $('.meta-menu-bottom');
//set cookie for future preference
//
//
//get cookie if first run or not
//
//
let upDown = 0,
duration = 1;
let tlshow = new TimelineMax({ paused: true });
tlshow.fromTo(menutop, duration, {top: '-40%' } ,{ top: 0, ease: Power3.easeInOut })
.fromTo(menubottom, duration, { bottom: '-40%' },{ bottom: 0, ease: Power3.easeInOut }, '-=' + duration);
let tlhide = new TimelineMax({ paused: true });
tlhide.fromTo(menutop, duration, { top: 0 } ,{ top: "-40%", ease: Power3.easeInOut })
.fromTo(menubottom, duration, { bottom: 0 },{ bottom: "-40%", ease: Power3.easeInOut }, '-=' + duration);
menutop.on("click",function(){
console.log("CLICKED MENUTOP");
if(upDown == 0) {
tlhide.restart();
upDown = 1;
}
else {
tlshow.restart();
upDown = 0;
}
});
codepen:https://codepen.io/giventofly/pen/RxMRMR
Chrome上的工作正常,在Firefox上,元菜单顶部/底部被推到左侧并重新排列为中心。
尝试使用webkit / moz前缀,甚至使用normalize.css但没有结果。
可能是什么?
答案 0 :(得分:1)
由于您使用position: absolute
作为顶部和底部菜单,因此您无需将display: flex
用于父元素。下面是工作代码的示例(稍微简化一点)。
var metaContainer = document.querySelector('.meta-container');
var menuTop = document.querySelector('.meta-menu-top');
menuTop.onclick = close;
function close() {
metaContainer.classList.toggle('closed');
}
&#13;
body {
overflow: hidden;
}
.meta-menu {
left: 50%;
transform: translateX(-50%);
}
.meta-menu-bottom,
.meta-menu-top {
height: 48%;
position: absolute;
width: 360px;
transition: 300ms;
}
.meta-menu-top {
align-items: center;
background: #252422;
color: #959595;
display: flex;
border-radius: 0px 0px 10px 10px;
justify-content: center;
opacity: 0.7;
text-align: center;
top: 0;
}
.meta-menu-top ul {
padding: 0;
margin-bottom: 30px;
}
.meta-menu-top li {
list-style-type: none;
}
.meta-title {
color: white;
bottom: 10px;
left: 0;
position: absolute;
width: 100%;
}
.meta-menu-bottom {
background: #eef1f5;
bottom: 0;
border-radius: 10px 10px 0px 0px;
color: white;
}
.closed .meta-menu-top {
top: -48%;
margin-top: 35px;
}
.closed .meta-menu-bottom {
bottom: -48%;
margin-bottom: 30px;
}
&#13;
<div id="container" class='container'>
<div class='meta-background'></div>
<section class='meta-container'>
<div class="meta-menu meta-menu-top">
<ul>
<li>testsas</li>
<li>fdadasdasdas</li>
<li>dsdasdsadasdsa</li>
</ul>
<div class="meta-title">WEBSITE</div>
</div>
<div class="meta-menu meta-menu-bottom"></div>
</section>
</div>
&#13;
答案 1 :(得分:0)