【发布时间】:2017-10-27 15:28:39
【问题描述】:
我在 jQuery 中有侧边导航操作:
$(function openSidebar()) {
document.getElementById("sidebar").style.width = "250px";
document.getElementById("wrapper").style.marginLeft = "250px";
}
function closeSidebar() {
document.getElementById("sidebar").style.width = "0";
document.getElementById("wrapper").style.marginLeft= "0";
}
我需要在移动设备上将宽度从 250 像素更改为 100%。如何在 jQuery 上获取它?
【问题讨论】:
-
为什么在 jQuery 中使用
document.getElementById? -
@PeterMader 我刚刚使用了w3schools.com/howto/howto_js_sidenav.asp 的解决方案,您可能有其他建议作为回报?
-
@FilipKolendo,使用 jQuery,您通常使用
$(...)和 selectors 在 DOM 中查找元素。在您的情况下,它将是$('#sidebar').css('width', '250px')。查看jQuery API documentation。
标签: javascript jquery html css twitter-bootstrap