看看这个设计灵感菜单:http://theblondeabroad.com
如何使用jQuery正确计算这种响应子菜单的宽度,尤其是在浏览器调整大小时?再加上主容器的绝对位置(左侧和顶部),使其保持在中心位置?
提前致谢。
答案 0 :(得分:1)
jQuery 的width()
方法将为您提供元素的计算宽度:
$(function(){
$('#menu li:has("ul")').each(function(){
alert($(this).width());
});
});
查看此链接以进一步阅读
答案 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
});
希望这有帮助!