添加溢出:仅在窗口大小为1366 * 768及以下时滚动

时间:2016-06-21 15:09:54

标签: javascript jquery html css

我有一个问题,想知道是否有人可以帮助我解决我遇到的问题。目前公司内联网系统没有响应。大多数员工都有一个更大的监控器,所以不是一个大问题。有一些员工正在使用最高分辨率为1366 * 768的笔记本电脑,这就是出现问题的地方。当用户点击"按钮时#34;弹出一个模态,但由于内部网系统没有响应,因此模式的底部对用户不可见。用户查看模式底部的唯一方法是将浏览器窗口的大小调整为低于75%。所以问题是,有没有办法让我添加一个溢出:只有当窗口(浏览器窗口)低于1366 * 768时滚动。我不想添加滚动条到模态,因为模态是在更大的屏幕上完美可见。

请参阅下面的CSS代码。

#divProductDetailsModal{
width: 1280px;
height: 662px;
margin-left: -640px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -360px;
/*overflow: scroll;*/
background: rgb(238,238,238); /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5 zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNjY2NjY2MiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(238,238,238,1)), color-stop(100%,rgba(204,204,204,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(238,238,238,1) 0%,rgba(204,204,204,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cccccc',GradientType=0 ); /* IE6-8 */
border: 0;

}

3 个答案:

答案 0 :(得分:1)

您可以使用CSS3媒体查询来检测窗口的大小:

@media (max-width: 1366px) and (max-height: 768px) {
    #divProductDetailsModal {
        overflow: scroll;

        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        width: auto;
        height: auto;
    }
}

当屏幕尺寸变小时,模态应该是灵活大小的,因此可以滚动。您无法滚动具有固定大小的内容。使模态灵活大小也可以使其适合屏幕甚至更小 1366 x 768的用户。

答案 1 :(得分:0)

您可以尝试使用媒体查询,只需在CSS中添加几行。

或者你可以用js获得窗口大小,一旦它低于1366 * 768就可以添加一些样式。

媒体查询更容易。

 @media screen and (max-width: 1366px) , screen and (max-height: 768px) {
  #divProductDetailsModal {
     overflow: scroll;
   }
}

答案 2 :(得分:0)

如果您在%中定义尺寸和位置,那么您不需要媒体查询,请尝试以下方法:



#divProductDetailsModal {
  /*Position fixed to remain always on the view and keep dimensions relative to the browser window - expected behavior for modals*/
  position:fixed;
  
  /*width and height to any % value and max width to keep the dimensions you have on large screens*/
  width: 80%;
  max-width:1280px;
  height: 662px;
  max-height:80%;
  
  /*overflow show scroll when needed*/
  overflow:auto;
  
  /*Position element and center on screen*/
  top: 10%;
  left: 10%;
  
  /*extra Look*/
  background: rgb(238, 238, 238);
  border: 0;
}
#divProductDetailsModal img {
  width:100%;
}

<div id="divProductDetailsModal">
  <img src="http://lorempixel.com/1024/1024">
</div>
&#13;
&#13;
&#13;