在调整大小事件上禁用 superfish
我正在尝试将 Superfish jQuery 插件与 Nathan Smith 的 adjustment.js 片段结合起来,该片段根据浏览器宽度动态加载不同的 CSS 文件。我想在移动模式下禁用/替换 Superfish 菜单,因为下拉菜单在那里没有任何意义。我尝试检测更改并禁用菜单,但我需要在窗口再次调整宽度时重新启用它。
这就是我所拥有的:
function htmlId(i, width) {
document.documentElement.id = 'pagesize_' + i;
}
var ADAPT_CONFIG = {
path: '/css/',
dynamic: true,
callback: htmlId,
range: [
'0px to 760px = mobile.css',
'760px = 960_12.css'
]
};
function sfMenu() {
$("#pagesize_1 ul.sf-menu").superfish({
delay: 800,
animation: {opacity:'show'},
speed: 'fast',
autoArrows: true,
dropShadows: true
});
}
$(document).ready(function(){
sfMenu();
});
基本原理是更改 resize
上 html 元素的 id(在 pagesize_0
和 pagesize_1
之间 - 有效)并使用 CSS 中的后代选择器来禁用菜单,但这不起作用。我尝试在 resize
上重新运行 sfMenu()
(上面未显示代码),但它似乎没有检查更改后的 DOM,意识到 pagesize_1
不再存在,然后优雅地失败(我认为这会达到我想要的效果)。
有什么想法吗?理想情况下,我想销毁 resize-to-mobile 上的 superfish
功能,然后在屏幕再次变大时重新设置它。
I'm trying to combine the Superfish jQuery plugin with Nathan Smith's adapt.js snippet, which dynamically loads in different CSS files depending on browser width. I want to disable/replace/something the Superfish menu when in mobile mode, because drop-downs don't make any sense there. I've attempted to detect the change and disable the menu, but I need it to re-enable when the window is resized wide again.
Here's what I have:
function htmlId(i, width) {
document.documentElement.id = 'pagesize_' + i;
}
var ADAPT_CONFIG = {
path: '/css/',
dynamic: true,
callback: htmlId,
range: [
'0px to 760px = mobile.css',
'760px = 960_12.css'
]
};
function sfMenu() {
$("#pagesize_1 ul.sf-menu").superfish({
delay: 800,
animation: {opacity:'show'},
speed: 'fast',
autoArrows: true,
dropShadows: true
});
}
$(document).ready(function(){
sfMenu();
});
The rationale was to change the id of the html element on resize
(between pagesize_0
and pagesize_1
- which works) and to use descendent selectors in CSS to disable the menu, but that doesn't work. I tried rerunning sfMenu()
on resize
(code not shown above), but it doesn't seem to inspect the changed DOM, realise pagesize_1
no longer exists, then fail gracefully (which I think would achieve the effect I'm after).
Any thoughts? Ideally I'd like to destroy the superfish
function on resize-to-mobile, then re-instate it when the screen is large again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SuperFish 有一个“销毁”方法(当然在最新的 1.7.3 版本中),您可以根据屏幕大小调用该方法来禁用它,然后使用 CSS 媒体查询重新设置导航样式。当您想再次启用 SuperFish 时,您也可以调用 SuperFish 的“init”方法:
这有望解释我正在谈论的内容:)
http: //cdpn.io/jFBtw
SuperFish has a 'destroy' method (certainly in latest 1.7.3 version) that you could call depending on screen size to disable it and then re-style the navigation using CSS media queries. You could also then call the 'init' method of SuperFish when you wanted to enable it again:
This should hopefully explain what I'm talking about :)
http://cdpn.io/jFBtw
我一直在玩同样的事情,从水平导航栏样式(窗口比子导航宽)到垂直下拉样式(子导航比窗口宽)到简单的 ol-list (主导航比窗口宽) 。
不确定它有多优雅,但最终 unbind() 和 removeAttr('style') 为我禁用了下拉菜单:
I've been playing around with the same thing, going from horizontal nav-bar style (window wider than subnav) to vertical drop-down style (subnav wider than window) to just plain-ol-list (main nav wider than window).
Not sure how elegant it is, but in the end unbind() and removeAttr('style') disabled the dropdowns for me: