javascript - How do I stop my menu from saving its state in the URL? -
i have menu when click on goes /#0 of page indicate has been opened, i'm wondering how either prevent showing or find alternative way of opening menu. here's menu trigger html:
<header class="cd-header"> <a href="#0" class="cd-3d-nav-trigger"> menu <span></span> </a> </header>
and full javascript file can found here
jquery(document).ready(function($){ //toggle 3d navigation $('.cd-3d-nav-trigger').on('click', function(){ toggle3dblock(!$('.cd-header').hasclass('nav-is-visible')); }); //select new item 3d navigation $('.cd-3d-nav').on('click', 'a', function(){ var selected = $(this); selected.parent('li').addclass('cd-selected').siblings('li').removeclass('cd-selected'); updateselectednav('close'); }); $(window).on('resize', function(){ window.requestanimationframe(updateselectednav); }); function toggle3dblock(addorremove) { if(typeof(addorremove)==='undefined') addorremove = true; $('.cd-header').toggleclass('nav-is-visible', addorremove); $('.cd-3d-nav-container').toggleclass('nav-is-visible', addorremove); $('main').toggleclass('nav-is-visible', addorremove).one('webkittransitionend otransitionend otransitionend mstransitionend transitionend', function(){ //fix marker position when opening menu (after window resize) addorremove && updateselectednav(); }); } //this function update .cd-marker position function updateselectednav(type) { var selecteditem = $('.cd-selected'), selecteditemposition = selecteditem.index() + 1, leftposition = selecteditem.offset().left, backgroundcolor = selecteditem.data('color'), marker = $('.cd-marker'); marker.removeclassprefix('color').addclass('color-'+ selecteditemposition).css({ 'left': leftposition, }); if( type == 'close') { marker.one('webkittransitionend otransitionend otransitionend mstransitionend transitionend', function(){ toggle3dblock(false); }); } } $.fn.removeclassprefix = function(prefix) { this.each(function(i, el) { var classes = el.classname.split(" ").filter(function(c) { return c.lastindexof(prefix, 0) !== 0; }); el.classname = $.trim(classes.join(" ")); }); return this; }; });
thanks in advance.
expanding on comment above, need prevent default action occurring.
$('.cd-3d-nav-trigger').on('click', function(e){ e.preventdefault(); toggle3dblock(!$('.cd-header').hasclass('nav-is-visible')); });
you can return false
click handler prevent default action and stop propagation of event parent elements.
Comments
Post a Comment