JQuery if statement based on width

I'm trying to create a menu that opens and closes slightly. If the menu is 20% wide, I want the items to show. If the menu is 10% wide, I want the items to be hidden. A menu button is used to expand and collapse the menu. I can get the menu collapsing but I try to add anything that expands the menu based on the width it breaks. $(".icon-menu").click(function() { $(".sidebar").animate({ width: "10%", }, 200 ); $(".sidebar ul").css("display", "none"), $(".menu-heading").css("display", "none"); }); if (".sidebar").css("width") == "10%"{ $(".icon-menu").click(function() { $(".sidebar").animate({ width: "20%", }, 200 ); $(".sidebar ul").css("display", "visible"), $(".menu-heading").css("display", "visible"); });
Your line if (".sidebar").css("width") == "10%" is not proper JavaScript to begin with and you wanna have 1 click function that checks the width rather than different click functions depending on the width.

以上就是JQuery if statement based on width的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏