0

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

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

提前致谢。

4

2 回答 2

1

jQuerywidth()方法会给你一个元素的计算宽度:

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

查看此链接以进一步阅读

jQuery

于 2015-08-12T07:07:22.613 回答
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
});

希望这可以帮助!

于 2015-08-12T07:07:24.113 回答