【发布时间】:2017-06-09 01:18:53
【问题描述】:
尝试检查位置固定元素的宽度。单击菜单图标容器后,抽屉的宽度应从 0% 增加到 18%。如果单击文档的正文,抽屉应该关闭,但仅当抽屉的宽度为 18% 时。当我尝试将抽屉的宽度记录到控制台时,我得到了 0px,即使结果是在抽屉展开后记录的。有人知道我错过了什么吗?
$("#menu-icon-container").click(function(){
$("#drawer-menu-wrapper").animate({width:'18%'},'fast');
$("#drawer-home-text").text("Home");
$("#drawer-products-text").text("Products");
$("#body-wrapper").css("opacity","0.5");
console.log($("#drawer-menu-wrapper").css("width"));
});
$("#close-icon-container").click(function(){
$("#drawer-menu-wrapper").animate({width:'0%'},'fast');
$("#drawer-home-text").text("");
$("#drawer-products-text").text("");
$("#body-wrapper").css("opacity","1");
});
$("#body-wrapper").click(function(){
if ($("#drawer-menu-wrapper").css("width")!="0px"){
$("#drawer-menu-wrapper").animate({width:'0%'},'fast');
$("#drawer-home-text").text("");
$("#drawer-products-text").text("");
$("#body-wrapper").css("opacity","1");
}
});
【问题讨论】:
-
为什么你认为你在抽屉展开之后记录它?该代码指示您在动画开始时(而不是结束时)转储值。 Animate 以异步方式运行。
标签: javascript jquery html css frontend