0

我想知道是否有人可以帮助我。

下面的代码是我网页的一部分,它为谷歌地图创建了一个侧边栏。

// == rebuilds the sidebar to match the markers currently displayed == 
function makeSidebar() {
  var html = "";
  for (var i = 0; i < gmarkers.length; i++) {
    if (gmarkers[i].getVisible()) {
      html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + " - " + gmarkers[i].mydescription + '<\/a><br>';
    }
  }
  document.getElementById("sidebar").innerHTML = html;
}

我遇到的问题是,随着地图标记列表的增长,滚动页面以查看所有条目变得越来越困难。

我想做的是创建一个垂直滚动条,以便更轻松地导航。我已经对此进行了一些阅读,我认为我说如果这是在 adiv我可以使用overflow? 是正确的。但我不确定在使用 Javascript 时如何复制。

我只是想知道是否有人可以看看这个并提供一些关于我如何解决这个问题的指导。

非常感谢和亲切的问候

4

1 回答 1

1

To allow a div to be scrolled, simple add the css property overflow with the value of scroll - you will need to provide the height attribute too

example here

If your sidebar element was a div you could just apply the following :

#sidebar {
   overflow: scroll;
   height: 400px;
   width: 100px;
}

You would need to change the height and width values as you require ....

A value of scroll means :

The content is clipped and desktop browsers use scrollbars, whether or not any content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. Printers may print overflowing content.

Docs for the overflow property here

于 2012-07-09T13:10:59.347 回答