gpt4 book ai didi

javascript - 如何创建 map 并将其附近的div固定,以便div的内容随着滚动而移动?

转载 作者:行者123 更新时间:2023-11-30 06:22:03 31 4
gpt4 key购买 nike

我在右侧 div 中有一些房屋,在左侧有一张 map ,我想创建类似于以下地址的内容: https://www.hometogo.com/search/5460aea1318a0?campaign=widget/all/a/wimdu/5460aea1318a0&w-message=1&persons=2&arrival=2018-10-10&duration=9

我希望我的 map 像顶部链接一样固定,并且应该能够通过滚动查看更多房屋而且我不希望带有 showResultSearch 类的 div 有滚动条。我该怎么做?

var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];

var map = new google.maps.Map(document.getElementById('searchMap'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});

google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
.searchContainer {
overflow: hidden;
position: relative;
}

.searchResults {
width: 60%;
float: right;
border-top: 1px solid #eee;
}

.showResultSearch {
clear: both;
border-top: 1px solid #eee;
padding-right: 30px;
padding-left: 30px;
margin-left: auto;
margin-right: auto;
max-height: 600px;
overflow-y: auto;
}

.searchMap {
border: 1px solid lightgray;
float: right;
width: 40%;
height: 600px;
}

#searchMap {
width: 100%;
height: 100%;
}

.row {
margin-left: -15px;
margin-right: -15px;
}

.col-sm-6 {
padding-left: 15px;
padding-right: 15px;
width: 50%;
float: right;
}

.specialOffer {
width: 100%;
}
<header></header>
<div class="searchContainer">
<div class="searchResults">

<div class="showResultSearch">
<div class="row" id="houses">
<div class="col-sm-6">
<figure class="specialOffer">
<a href="#" class="images">
<img src="Images/house1.jpg" />
</a>
<figcaption>
<div class="title-house">
<a href="#" class="house-name">
<h3>house1 </h3>
</a>
</div>
</figcaption>
</figure>

</div>
<div class="col-sm-6">
<figure class="specialOffer">
<a href="#" class="images">
<img src="Images/house2.jpg" />
</a>
<figcaption>
<div class="title-house">
<a href="#" class="house-name">
<h3>house2 </h3>
</a>
</div>
</figcaption>
</figure>

</div>
<div class="col-sm-6">
<figure class="specialOffer">
<a href="#" class="images">
<img src="Images/house1.jpg" />
</a>
<figcaption>
<div class="title-house">
<a href="#" class="house-name">
<h3>house3 </h3>
</a>
</div>
</figcaption>
</figure>

</div>
<div class="col-sm-6">
<figure class="specialOffer">
<a href="#" class="images">
<img src="Images/house1.jpg" />
</a>
<figcaption>
<div class="title-house">
<a href="#" class="house-name">
<h3>house4 </h3>
</a>
</div>
</figcaption>
</figure>

</div>
</div>

</div>
</div>
<div class="searchMap">
<div id="searchMap"></div>
</div>
</div>
<footer>

</footer>

最佳答案

从 .searchContainer 中删除 position: relative 并添加 display: flex。

设置位置:固定在#searchMap上

据我了解您的问题,效果很好。至于滚动条,请尝试使用溢出(溢出:隐藏)或宽度和高度。

关于javascript - 如何创建 map 并将其附近的div固定,以便div的内容随着滚动而移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52605902/

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