我可以基于 HTML 类为菜单效果编写 if/else 条件吗?
Can i write an if/else condition for a menu effect based on HTML class?
我正在使用带有以下jQuery的megamneu。当前的菜单效果是"悬停滑动",我想在找到手机或平板电脑时将悬停滑动效果更改为单击滑动。我的HTML头中有html.mobile和html.tablet。我将如何根据我的 html 类编写该条件
我想要一个条件,说明,如果 html.mobile 或 html.tablet ,则菜单效果为"clide-slide",否则菜单效果为"悬停幻灯片"
$(document).ready(function($){
$('.megamenu').megaMenuReloaded({
menu_speed_show : 300, // Time (in milliseconds) to show a drop down
menu_speed_hide : 0, // Time (in milliseconds) to hide a drop down
menu_speed_delay : 100, // Time (in milliseconds) before showing a drop down
menu_effect : 'hover_slide', // Drop down effect, choose between 'hover_fade', 'hover_slide', 'click_fade', 'click_slide', 'open_close_fade', 'open_close_slide'
menu_easing : 'jswing', // Easing Effect : 'easeInQuad', 'easeInElastic', etc.
menu_click_outside : 1, // Clicks outside the drop down close it (1 = true, 0 = false)
menu_show_onload : 0, // Drop down to show on page load (type the number of the drop down, 0 for none)
menubar_trigger : 0, // Show the menu trigger (button to show / hide the menu bar), only for the fixed version of the menu (1 = show, 0 = hide)
menubar_hide : 0, // Hides the menu bar on load (1 = hide, 0 = show)
menu_responsive : 1, // Enables mobile-specific script
menu_carousel : 0, // Enable / disable carousel
menu_carousel_groups : 0 // Number of groups of elements in the carousel
});
});
使用条件(又名"三元")运算符。
$(document).ready(function($){
$('.megamenu').megaMenuReloaded({
menu_speed_show : 300, // Time (in milliseconds) to show a drop down
menu_speed_hide : 0, // Time (in milliseconds) to hide a drop down
menu_speed_delay : 100, // Time (in milliseconds) before showing a drop down
menu_effect : $("html.mobile, html.tablet").length ? 'click_slide' : 'hover_slide', // Drop down effect, choose between 'hover_fade', 'hover_slide', 'click_fade', 'click_slide', 'open_close_fade', 'open_close_slide'
menu_easing : 'jswing', // Easing Effect : 'easeInQuad', 'easeInElastic', etc.
menu_click_outside : 1, // Clicks outside the drop down close it (1 = true, 0 = false)
menu_show_onload : 0, // Drop down to show on page load (type the number of the drop down, 0 for none)
menubar_trigger : 0, // Show the menu trigger (button to show / hide the menu bar), only for the fixed version of the menu (1 = show, 0 = hide)
menubar_hide : 0, // Hides the menu bar on load (1 = hide, 0 = show)
menu_responsive : 1, // Enables mobile-specific script
menu_carousel : 0, // Enable / disable carousel
menu_carousel_groups : 0 // Number of groups of elements in the carousel
});
});
你应该能够这样做:
if($(body).width() < 768)) {
$('.megamenu').megaMenuReloaded({
clide-slide : 'hover_slide', // Drop down effect, choose between 'hover_fade'
});
其中768是平板电脑的宽度。手机也可以这样做。
相关文章:
- 如何在ReactJS JSX中执行嵌套的if-else语句
- Javascript Return and if/else
- JavaScript if-else 速记错误
- 如何检查if/else语句中的随机条件
- 在javascript中创建数组,而不是if.else
- Javascript If else 只返回 TRUE 或只返回 FALSE
- jquery if else不返回警报消息
- 在Javascript中为if/else语句添加OR
- If Else Java Script HTML
- jQuery/Javascript foreach If/Else |如果为空(不执行任何操作)Else(显示forea
- 我应该如何应用if-else条件来向具有不同用户角色的人显示不同的菜单
- geoTest函数-创建if/else语句
- JavaScript中的温度转换器(IF ELSE条件)
- Jquery/Javascript使用IF/ELSE语句更改img SRC
- 编写if-else语句的更好方法
- 在if/else语句中显示DIV
- PHP If Else-隐藏按钮
- JavaScript if/else未按预期操作
- if/else运算符未更改
- 名称不能以''jquery-if-else条件中的字符