我设法让我的matchmedia查询部分工作,即它适用于窗口加载,但无法在调整大小时工作。我真的很新(因此这是一个糟糕的问题),所以放轻松,说话慢。我试图在屏幕更改或页面加载时触发它。
http://codepen.io/anon/pen/XJZOMw
function mediaqueryresponse(screencheck){
if (screencheck.matches){
function introHeight(){
var introheight = document.getElementById("bottom").offsetHeight;
document.getElementById("introtext").style.top =(180 - introheight) + "px";
//document.write (introheight);
}
//document.onresize = introHeight;
window.onresize = introHeight;
}
}
var screencheck = window.matchMedia("all and (max-width: 419px)");
mediaqueryresponse(screencheck); // call listener function explicitly at run time
screencheck.addListener(mediaqueryresponse); // attach listener function to listen in on state changes
谢谢,对不起,如果这是重复或只是废话编程和/或写得不好或在错误的地方。