如何计算流体宽度导航菜单的正确宽度?

时间:2015-08-12 07:02:59

标签: jquery css submenu responsiveness

看看这个设计灵感菜单:http://theblondeabroad.com

如何使用jQuery正确计算这种响应子菜单的宽度,尤其是在浏览器调整大小时?再加上主容器的绝对位置(左侧和顶部),使其保持在中心位置?

提前致谢。

2 个答案:

答案 0 :(得分:1)

jQuery width()方法将为您提供元素的计算宽度:

$(function(){
  $('#menu li:has("ul")').each(function(){
    alert($(this).width());
  });
});

查看此链接以进一步阅读

Jquery

答案 1 :(得分:1)

您需要使用resize事件:

$(window).resize(function() {
   var window_width = $(this).width();
   //and then set the width of the dropdown accordingly
   $('#yourdropdown').css('width',window_width/4+"px");//or something that you require
});

希望这有帮助!

相关问题