我目前正在使用 Soundcloud API 来提取图像并跟踪歌曲的链接。我目前在单击专辑图像时通过模式窗口显示曲目信息。但是,对于屏幕底部的歌曲,模态窗口只出现在屏幕顶部,需要用户向上滚动才能看到曲目信息。可能与 css 定位有关,但删除 position:absolute 仅将模态窗口放在所有专辑图像的底部,需要向下滚动。我怎样才能做到这一点,以便用户单击图像将打开并在他们当前所在的位置启动模态窗口,而无需滚动?欢迎 Javascript / jquery /css 回答所有问题。
我的 CSS:
#modal { 
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    position: absolute;
    top: 0;
    left: 0;
}
#trackinfo {
    width:380px;
    height: 180px;
    padding: 20px; 
    margin-right: auto;
    margin-left: auto;
    margin-top: 100px;
    box-shadow: 10px 10px 5px;
    border-radius: 15px;
    text-align: center;
    background: #c4e5c1;
    font-family: Rockwell, "Courier Bold", Courier, Georgia, Times, "Times New Roman", serif;
}
.hidden { 
    display:none;
}
我用于显示和隐藏模式的 Javascript:
  function doSearch() {
    var searchTerm = document.getElementById('search').value;
    // Search soundcloud for artists
    SC.get('/tracks', { q: searchTerm}, function(tracks) {
      for(track in tracks) {
        var img = document.createElement('img');
        img.setAttribute("src", (tracks[track]["artwork_url"]));
        var title = tracks[track].title.replace("'", "\\\'").replace("\"", "\\\"");
        linky = document.createElement('a');
        linky.setAttribute("href", (tracks[track].permalink_url));
        console.log(linky);
        img.setAttribute("onclick", "showTrackInfo('" + title + "\\n"+ tracks[track].uri + " " + "\\n\\n(click to close) " + "')"); 
        console.log(img);
        if (tracks[track]["artwork_url"] == null) {
          console.log(""); } 
        else { 
          var Catalog = document.getElementById('catalog');
          Catalog.appendChild(img);
          $('div#catalog').append('<a href="'+linky+'"><img src="http://i.imgur.com/rGdvfl7.png"></a>');
        }
      }
    });
  };
  function showTrackInfo(track) { 
    var trackInfoElement = document.getElementById("trackinfo");
    trackInfoElement.appendChild(document.createTextNode(track));
    var modal = document.getElementById("modal"); 
    modal.setAttribute("class", ""); 
  }
  function hidemodal() { 
    var trackInfoElement = document.getElementById("trackinfo");
    trackInfoElement.childNodes;
    while ( trackInfoElement.firstChild ) trackInfoElement.removeChild( trackInfoElement.firstChild );
    var modal = document.getElementById("modal");
    modal.setAttribute("class", "hidden"); 
  }
这些功能都运行良好,我只需要知道如何在单击时定位模态框,以便用户无需滚动即可查看轨道信息。非常感谢任何帮助。