gpt4 book ai didi

javascript - 使 DIV 固定,这样它就不会滚动

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:04 24 4
gpt4 key购买 nike

我有一张 map 和一张 map 下的列表。当我滚动时,我希望 map 保持固定,但 map 下方的列表可以滚动。

enter image description here

我的 HTML 是:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
<title>Starter Template - Materialize</title>

<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="css/leaflet.css" type="text/css" rel="stylesheet" media="screen,projection" />

</head>

<body>
<div class="navbar-fixed ">

<nav class="orange " role="navigation">
<div id="replaceBar" class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo">Local Market</a>
<ul class="right hide-on-med-and-down left">
<li><a href="stats.html">Statistics</a></li>
</ul>

<ul id="nav-mobile" class="side-nav left">
<!-- Statistics Drop Down Start -->
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li>
<a class="collapsible-header"> My Statistics<i class="mdi-navigation-arrow-drop-down right"></i></a>
<div class="collapsible-body">
<ul>
<li><a href="stats.html">Basic Stats</a></li>
<li><a href="myBreweries.html"> My Top Breweries</a></li>
<li><a href="myStyles.html">My Top Styles</a></li>
<li><a href="myTaste.html">My Top Tastes</a></li>
</ul>
</div>
</li>
</ul>
</li>
<!-- Statistics Drop Down End -->
<li><a href="list.html">My Lists</a></li>
<!-- Map Drop Down Start -->
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li>
<a class="collapsible-header">My Maps<i class="mdi-navigation-arrow-drop-down right"></i></a>
<div class="collapsible-body">
<ul>
<li><a href="mapTapped.html">Breweries Tapped</a></li>
<li><a href="mapVisited.html">Breweries Visited</a></li>
</ul>
</div>
</li>
</ul>
</li>
<!-- Map Drop Down End -->
<!-- Discover Drop Down Start -->
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li>
<a class="collapsible-header">Discover<i class="mdi-navigation-arrow-drop-down right"></i></a>
<div class="collapsible-body">
<ul>
<li><a href="topBeers.html">Top Beers</a></li>
<li><a href="topBreweries.html">Top Breweries</a></li>
<li><a href="topStyles.html">Top Styles</a></li>
<li><a href="topTaste.html">Top Tastes</a></li>
</ul>
</div>
</li>
</ul>
</li>
<!-- Discover Drop Down End -->
<!-- Drink Local Drop Down Start -->
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li>
<a class="collapsible-header">Breweries Tapped<i class="mdi-navigation-arrow-drop-down right"></i></a>
<div class="collapsible-body">
<ul>
<li><a href="localBeers.html">Top Local Beers</a></li>
<li><a href="nearbyBreweries.html">Nearby Breweries</a></li>

</ul>
</div>
</li>
</ul>
</li>
<!-- Drink Local Drop Down End -->
</ul>

<a href="#" data-activates="nav-mobile" class="button-collapse"><img style="vertical-align: middle;" src="img/menuIcon.png" height="30" width="30"></a>

<ul id="search" class="right valign-wrapper">
<li class="valign">
<a href="#"> <img style="vertical-align: middle;" src="img/searchIcon.png" height="30" width="30"></a>
</li>

</ul>
</div>
</nav>


</div>


<div id="map" style="height: 300px;" style="position:fixed;"></div>


<div id="replace"> </div>





<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content center">
<div>
<span class="card-title">Searching Stock</span>
</div>
<div id="load" class="preloader-wrapper big active ">
<div class="spinner-layer spinner-yellow-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>

</div>






</body>

</html>

最佳答案

嗯....

#topDivthatNeedstoStay { 
width:100%;
top:0;
left:0;
height: $height; // variable replace with actual
position: fixed; // boom
background: $yellow; // variable replace with actual
}
#elementYouwantoScroll {
width:100%;
height:$height; // variable replace with actual
overflow-y:scroll; // scroll
-webkit-overflow-scrolling: touch; // for mobile might as well pop this in as well ;)
}

关于javascript - 使 DIV 固定,这样它就不会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32081734/

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