0

I have this idea for an website where the background is made up of google maps. 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.

Now my question is: how do I make the map "move"/pan depending on scroll position?

Any help is greatly appreciated :)

4

1 回答 1

1

使用.panToAPI 的方法(https://developers.google.com/maps/documentation/javascript/reference#Map)并从滚动事件中调用它

就像是

$(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
});
于 2013-04-21T15:08:41.540 回答