【问题标题】:Javascript modal window requires scroll down to seeJavascript模态窗口需要向下滚动才能看到
【发布时间】:2013-04-28 16:52:37
【问题描述】:

我目前正在使用 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"); 
  }

功能都很好,我只需要知道如何在点击时定位模态框,这样用户就不需要滚动来查看轨道信息。非常感谢任何帮助。

【问题讨论】:

    标签: javascript jquery scroll popup modal-dialog


    【解决方案1】:

    在对话框中尝试position: fixed;,无论它们在哪里,都应该让它填满页面

    【讨论】:

    • 天哪,万岁!如此简单的修复!非常感谢。
    猜你喜欢
    • 2015-11-23
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多