【问题标题】:How to calculate the correct width for a fluid-width nav menu? [closed]如何计算流体宽度导航菜单的正确宽度? [关闭]
【发布时间】:2015-08-12 15:44:36
【问题描述】:

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

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

提前致谢。

【问题讨论】:

  • 你能给我们看看子菜单吗
  • theblondeabroad.com 子菜单中有图片的人。我喜欢响应式地计算该子菜单的容器。所以从 1100px 容器向下调整大小。

标签: jquery css submenu responsiveness


【解决方案1】:

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

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

查看此链接以进一步阅读

Jquery

【讨论】:

    【解决方案2】:

    你需要使用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
    });
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 2011-10-05
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多