首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >window.location光滑涡旋

window.location光滑涡旋
EN

Stack Overflow用户
提问于 2014-02-25 20:43:42
回答 2查看 873关注 0票数 0

我有一个有标记的谷歌地图,当我点击同一个页面中的#锚标签时。一切运行良好,我只是希望当标记是点击锚不是跳跃,而是平滑滚动。有什么办法可以做到这一点吗?

代码语言:javascript
复制
<script>

    var maps;
    function initialise() 
    {



    var stylez = [
    {
      featureType: "all",
      elementType: "all",
      stylers: [

        { saturation: -100 } // <-- THIS
      ]
    }
];

    var mapOptions = {
    zoom: 8,
    center:  new google.maps.LatLng(10.628216,-61.301394),
     mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'tehgrayz']
}

  } ;
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);       
var mapType = new google.maps.StyledMapType(stylez, { name:"Grayscale" });    
map.mapTypes.set('tehgrayz', mapType);
map.setMapTypeId('tehgrayz');       


    // -------------- MARKER 1
    var marker1 = new google.maps.Marker({
    position: new google.maps.LatLng(10.658562,-61.522754),
    map: map,
    icon: 'images/mapicon.png'
    });


    // MARKER 1'S INFO WINDOW

    var infowindow1 = new google.maps.InfoWindow({
    content: 'University of Trinidad and Tobago <br />John Donaldson Campus<br />'
    });
    // End of infowindow code


        google.maps.event.addListener(marker1, 'click', function() {
  infowindow1.open(map, marker1);
  window.location = "#uttjdc";

});


    // -------- END OF 1st MARKER


    // -------------- MARKER 2
    var marker2 = new google.maps.Marker({
    position: new google.maps.LatLng(10.267817,-61.465055),
    map: map,
    icon: 'images/mapicon.png'
    });

    // MARKER 2'S INFO WINDOW
    var infowindow2 = new google.maps.InfoWindow({
    content: 'National Academy for the Performing Arts<br /> South Campus<br />'
    });
    // End of infowindow code

    // Adding a click event to the marker
    google.maps.event.addListener(marker2, 'click', function() {
    // Calling the open method of the infoWindow
   infowindow2.open(map, marker2);
     window.location = "#uttsapa";
    });
    // -------- END OF 2nd MARKER


    // -------------- MARKER 3
    var marker3 = new google.maps.Marker({
    position: new google.maps.LatLng(11.18257,-60.739463),
    map: map,
        icon: 'images/mapicon.png'

    });

    // MARKER 3'S INFO WINDOW
    var infowindow3 = new google.maps.InfoWindow({
    content: 'University of Trinidad and Tobago<br />Scarborough Campuste'
    });
    // End of infowindow code

    // Adding a click event to the marker
    google.maps.event.addListener(marker3, 'click', function() {
    // Calling the open method of the infoWindow
    infowindow3.open(map, marker3);
      window.location = "#utttobago";
    });
    // -------- END OF 3rd MARKER

    }
            google.maps.event.addDomListener(window, 'load', initialise); // Execute our 'initialise' function once the page has loaded. 
            google.maps.event.addDomListener(window, "resize", function() {
 var center = map.getCenter();
 google.maps.event.trigger(map, "resize");
 map.setCenter(center); 
})
</script>

HTML

代码语言:javascript
复制
<div id="uttsapa">

    <div class="container-fullhub">
    <div class="container">
    <h2 class="hubhead text-center"><img src="images/hubicon.png "> Location 1
    </h2>
    <p class="hubadd text-center">
    Adress 1
    </p>
    </div>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-25 20:44:37

你试过用jquery.scrollTo插件吗?它能满足你的需要。

票数 1
EN

Stack Overflow用户

发布于 2014-02-25 21:42:03

这就是你对http://css-tricks.com/snippets/jquery/smooth-scrolling/的追求

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22025750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档