denishvachhani,
Since you can’t hover on a touch screen (yet), you have two options to show submenu.
- You can show all menu links using css and some jQuery.
CSS Code:
/* CSS */
@media screen and (max-width: 760px) {
#rtp-nav-menu li { text-align: left; }
#rtp-nav-menu li ul { display: block; }
#rtp-nav-menu ul.sub-menu { background: #EEEEEE; border: 0; left: 0; position: relative; top: 0; width: 100%; }
#rtp-nav-menu ul.sub-menu li { border: 0; padding-left: 20px; }
#rtp-nav-menu ul.sub-menu a { border: 0; }
}
jQuery Code:
jQuery( document ).ready(function() {
var nav_btn = '';
/* prepend menu icon */
jQuery('#rtp-primary-menu').prepend(nav_btn);
jQuery("#rtp-nav-menu li a").each(function() {
if (jQuery(this).next().length > 0) {
jQuery(this).addClass("parent");
};
})
jQuery(".rtp-nav-btn").click(function(e) {
e.preventDefault();
jQuery(this).toggleClass("active");
jQuery("#rtp-nav-menu").slideToggle();
});
});
- If you want to achieve hover effect, then write the code to set the click() and hover() events.
Here is the code:
CSS:
@media screen and (max-width: 760px) {
#rtp-nav-menu li:hover > ul { display: block; }
#rtp-nav-menu ul.sub-menu { background: #EEEEEE; border: 0; left: -1px; position: relative; top: 0; width: 100%; }
#rtp-nav-menu ul.sub-menu a { border: 0; }
#rtp-nav-menu ul.sub-menu li:first-child { border-top: 1px solid #DDD; }
}
jQuery:
var ww = document.body.clientWidth;
jQuery( document ).ready(function() {
var nav_btn = '';
/* prepend menu icon */
jQuery('#rtp-primary-menu').prepend(nav_btn);
jQuery("#rtp-nav-menu li a").each(function() {
if (jQuery(this).next().length > 0) {
jQuery(this).addClass("parent");
};
})
jQuery(".rtp-nav-btn").click(function(e) {
e.preventDefault();
jQuery(this).toggleClass("active");
jQuery("#rtp-nav-menu").slideToggle();
});
adjustMenu();
});
jQuery(window).bind('resize orientationchange', function() {
ww = document.body.clientWidth;
adjustMenu();
});
var adjustMenu = function() {
if (ww < 768) {
jQuery(".rtp-nav-btn").css("display", "inline-block");
if (!jQuery(".rtp-nav-btn").hasClass("active")) {
jQuery("#rtp-nav-menu").slideUp();
} else {
jQuery("#rtp-nav-menu").slideDown();
}
jQuery("#rtp-nav-menu li").unbind('mouseenter mouseleave');
jQuery("#rtp-nav-menu li a.parent").unbind('click').bind('click', function(e) {
// must be attached to anchor element to prevent bubbling
e.preventDefault();
jQuery(this).parent("li").toggleClass("hover");
});
}
else if (ww >= 768) {
jQuery(".rtp-nav-btn").css("display", "none");
jQuery("#rtp-nav-menu").slideDown();
jQuery("#rtp-nav-menu li").removeClass("hover");
jQuery("#rtp-nav-menu li a").unbind('click');
jQuery("#rtp-nav-menu li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
// must be attached to li so that mouseleave is not triggered when hover over submenu
jQuery(this).toggleClass('hover');
});
}
}
FYI: In 2nd option parent menu will not working not open in normal click.
Let me know your opinion