我已经设法让我的 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
感谢和抱歉,如果这是重复的或只是垃圾编程和/或写得不好或在错误的地方。