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