[英]How to pan google maps upon scroll position
I have this idea for an website where the background is made up of google maps. 我有一个网站背景由Google地图组成的想法。 As the user scrolls the map has to "move"/pan to a specific location.
当用户滚动时,地图必须“移动” /平移到特定位置。 I've found a script that will set google maps as my background so this is not the issue.
我找到了一个脚本,该脚本会将google地图设置为背景,所以这不是问题。
Now my question is: how do I make the map "move"/pan depending on scroll position? 现在我的问题是:如何根据滚动位置使地图“移动” /平移?
Any help is greatly appreciated :) 任何帮助是极大的赞赏 :)
Use the .panTo
method of the API ( https://developers.google.com/maps/documentation/javascript/reference#Map ) and call it from a scroll event 使用API( https://developers.google.com/maps/documentation/javascript/reference#Map )的
.panTo
方法,并从滚动事件中调用它
something like 就像是
$(document).on('scroll', function(){
// get current scroll position
var currentScroll = $('element that scrolls').scrollTop();
// calculate a new map point based on the currentScroll value
var latLng = new google.maps.LatLng(somelat, somelong);
// pan to it
map.panTo(latLng); // assuming map refers to the map object
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.