gpt4 book ai didi

jquery - 当下拉列表被附加时会创建微小的空间

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:45 26 4
gpt4 key购买 nike

当用户滚动网页时,大型下拉列表被附加(即粘性)时会创建一个小空间。如何解决?

$(document).ready(function() {
$("#flip").click(function() {
$("#panel").slideToggle("slow");
});

$("#flip1").click(function() {
$("#panel1").slideToggle("slow");
});
});
.affix {
top: 0;
width: 100%;
}

.navbar {
border-width: 0px;
-webkit-box-shadow: 0px 0px;
box-shadow: 0px 0px;
background-color: rgba(0, 0, 0, 0.0);
background-image: -webkit-gradient(linear, 50.00% 0.00%, 50.00% 100.00%, color-stop( 0%, rgba(0, 0, 0, 0.00)), color-stop( 100%, rgba(0, 0, 0, 0.00)));
background-image: -webkit-linear-gradient(270deg, rgba(0, 0, 0, 0.00) 0%, rgba(0, 0, 0, 0.00) 100%);
background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.00) 0%, rgba(0, 0, 0, 0.00) 100%);
}

.navbar-default .navbar-nav>li>a {
color: black;
}

.navbar-default .navbar-nav>.dropdown>a .caret {
border-top-color: #fff;
border-bottom-color: #fff;
}

.navbar-default .navbar-brand {
color: black;
}

.menu-large {
position: static !important;
}

.megamenu {
padding: 20px 0px;
width: 100%;
padding: 0;
margin: 0;
}

.megamenu>li>ul {
padding: 0;
margin: 0;
}

.megamenu>li>ul>li {
list-style: none;
}

.megamenu>li>ul>li>a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #333333;
white-space: normal;
}

.megamenu>li ul>li>a,
.megamenu>li ul>li>a:focus {
text-decoration: none;
color: #262626;
background-color: #f5f5f5;
}

.megamenu.disabled>a,
.megamenu.disabled>a,
.megamenu.disabled>a:focus {
color: #999999;
}

.megamenu.disabled>a,
.megamenu.disabled>a:focus {
text-decoration: none;
background-color: transparent;
background-image: none;
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
cursor: not-allowed;
}

.megamenu.dropdown-header {
color: #428bca;
font-size: 18px;
}

@media (max-width: 768px) {
.megamenu {
margin-left: 0;
margin-right: 0;
}
.megamenu>li {
margin-bottom: 30px;
}
.megamenu>li:last-child {
margin-bottom: 0;
}
.megamenu.dropdown-header {
padding: 3px 15px !important;
}
.navbar-nav .open .dropdown-menu .dropdown-header {
color: #fff;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li class="dropdown menu-large">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="flip1"> Product Listing <b class="caret"></b> </a>
<ul class="dropdown-menu megamenu row" data-spy="affix" data-offset-top="197" id="panel1">
<li>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="http://placehold.it/150x120" />
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="http://placehold.it/150x120" />
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="http://placehold.it/150x120" />
</a>
</div>
<div class="col-sm-6 col-md-3">
<a href="#" class="thumbnail">
<img src="http://placehold.it/150x120" />
</a>
</div>
</li>
</ul>
</li>

<li class="dropdown menu-large">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="flip">Categories <b class="caret"></b></a>
<ul class="dropdown-menu megamenu row" data-spy="affix" data-offset-top="197" id="panel">
<li class="col-sm-3">
<ul>
<li class="dropdown-header">Glyphicons</li>
<li><a href="#">Available glyphs</a></li>
<li class="disabled"><a href="#">How to use</a></li>
<li><a href="#">Examples</a></li>
<li class="divider"></li>
<li class="dropdown-header">Dropdowns</li>
<li><a href="#">Example</a></li>
<li><a href="#">Aligninment options</a></li>
<li><a href="#">Headers</a></li>
<li><a href="#">Disabled menu items</a></li>
</ul>
</li>
<li class="col-sm-3">
<ul>
<li class="dropdown-header">Button groups</li>
<li><a href="#">Basic example</a></li>
<li><a href="#">Button toolbar</a></li>
<li><a href="#">Sizing</a></li>
<li><a href="#">Nesting</a></li>
<li><a href="#">Vertical variation</a></li>
<li class="divider"></li>
<li class="dropdown-header">Button dropdowns</li>
<li><a href="#">Single button dropdowns</a></li>
</ul>
</li>
<li class="col-sm-3">
<ul>
<li class="dropdown-header">Input groups</li>
<li><a href="#">Basic example</a></li>
<li><a href="#">Sizing</a></li>
<li><a href="#">Checkboxes and radio addons</a></li>
<li class="divider"></li>
<li class="dropdown-header">Navs</li>
<li><a href="#">Tabs</a></li>
<li><a href="#">Pills</a></li>
<li><a href="#">Justified</a></li>
</ul>
</li>
<li class="col-sm-3">
<ul>
<li class="dropdown-header">Navbar</li>
<li><a href="#">Default navbar</a></li>
<li><a href="#">Buttons</a></li>
<li><a href="#">Text</a></li>
<li><a href="#">Non-nav links</a></li>
<li><a href="#">Component alignment</a></li>
<li><a href="#">Fixed to top</a></li>
<li><a href="#">Fixed to bottom</a></li>
<li><a href="#">Static top</a></li>
<li><a href="#">Inverted navbar</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<h1>Responsive Mega Dropdown</h1>
<h2>Responsive Mega Dropdown</h2>
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<h4>Responsive Mega Dropdown</h4>
<br />
<h5>Responsive Mega Dropdown</h5>
<h1>Responsive Mega Dropdown</h1>
<h2>Responsive Mega Dropdown</h2>
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<h4>Responsive Mega Dropdown</h4>
<br />
<h5>Responsive Mega Dropdown</h5>

<h1>Responsive Mega Dropdown</h1>
<h2>Responsive Mega Dropdown</h2>
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<h4>Responsive Mega Dropdown</h4>
<br />
<h5>Responsive Mega Dropdown</h5>

<h1>Responsive Mega Dropdown</h1>
<h2>Responsive Mega Dropdown</h2>
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<br />
<h1>Responsive Mega Dropdown</h1>
<br />
<h4>Responsive Mega Dropdown</h4>
<br />
<h5>Responsive Mega Dropdown</h5>

最佳答案

根据将您的代码加载到我的浏览器时我能够看到的内容,我发现修复它的最简单方法是在您的词缀类中设置 top: -1px,从而为您提供 .affix { top: -1px;宽度:100%; }。这告诉浏览器将元素放置在视口(viewport)顶部一像素之外,确保不存在间隙。

我希望我对为什么 0px 不起作用有一个明确的答案,因为我坚信它应该,但使用 -1px 似乎可以解决这个问题,而不会实际丢失菜单中的任何空间。

关于jquery - 当下拉列表被附加时会创建微小的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32396829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com