Superfish 水平菜单。如何测量宽度
我正在使用 superfish 在我的网站上创建水平菜单。
菜单项总是会有所不同,因为内容非常动态。菜单项不应具有固定宽度。
当显示的菜单项足够填满网站的整个宽度时,将显示最后一个名为“更多项目”的菜单。
我将如何测量每个菜单项(li 标签)的宽度,以便我可以限制显示的项目?
问题是我不能依赖某种字体来实现这一点。字体必须是访客机器上可用的任何字体。
感谢您的意见
I am using superfish to create a horizontal menu on my website.
The menu items will always vary, as the content is very dynamic. The menu items should not have a fixed width.
When the enough menu items are displayed to fill the entire width of the website, a last menu called 'More Items' will be shown.
How would I go about measuring the width of each menu item (li tag), so that i can limit the items shown?
The problem is that I can not depend on a certain font to achieve this. Font's must be, whatever is available on the visitors machine.
Thanks for your input
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法...
示例 jsfiddle
在中间部分我将每个菜单项的宽度相加,当满足阈值(最大宽度)时,我将返回这些菜单项,以便我可以将它们添加到“更多项目”菜单(在最后一步中)
Here's one way to do this...
example jsfiddle
In that middle segment I'm totaling up the widths of each menu item and when a threshold is met (the maxWidth) I'm returning those menu items so that I can add them to the "More Items" menu (in the final step)