jquery - Getting CSS/Javascript menu to recognize links properly -
i have found menu , have integrated local (wordpress) site. code pen fork
everything works should far animation, ect. however, when add link
i have tried both relative , absolute paths link well. -- see codepen link "start"-->"menu 1"-->"sub menu 1" -- hover on can see have added link of http://www.google.com/ test, when clicked not go site.
i appreciate pointers - , sorry if simple.
here full code: (also contained on code pen link)
html:
<div class="radmenu"><a href="#" class="show" >start</a> <ul> <li> <a href="#" class="">menu 1</a> <ul> <li><a href="http://www.google.com">sub menu 1</a></li> <li><a href="#">sub menu 2</a></li> <li><a href="#">sub menu 3</a></li> <li><a href="#">sub menu 4</a></li> <li><a href="#">sub menu 5</a></li> </ul> </li> <li> <a href="#">menu 2</a> <ul> <li><a href="#">sub menu 1</a></li> <li><a href="#">sub menu 2</a></li> <li><a href="#">sub menu 3</a></li> <li><a href="#">sub menu 4</a></li> <li><a href="#">sub menu 5</a></li> </ul> </li> <li> <a href="#">menu 3</a> <ul> <li><a href="#">sub menu 1</a></li> <li><a href="#">sub menu 2</a></li> <li><a href="#">sub menu 3</a></li> <li><a href="#">sub menu 4</a></li> <li><a href="#">sub menu 5</a></li> </ul> </li> <li> <a href="#">menu 4</a> <ul> <li><a href="#">sub menu 1</a></li> <li><a href="#">sub menu 2</a></li> <li><a href="#">sub menu 3</a></li> <li><a href="#">sub menu 4</a></li> <li><a href="#">sub menu 5</a></li> </ul> </li> <li> <a href="#">menu 5</a> <ul> <li><a href="#">sub menu 1</a></li> <li><a href="#">sub menu 2</a></li> <li><a href="#">sub menu 3</a></li> <li><a href="#">sub menu 4</a></li> <li><a href="#">sub menu 5</a></li> </ul> </li> </ul> </div>
css:
@import "compass/css3"; $sub-menus : 5; body { background: url(http://www.scenicreflections.com/files/hazy_forest_road_wallpaper_qoek0.jpg) } .radmenu { position: absolute; display:flex; align-items: center; justify-content: center; width: 100%; height: 100%; > { top: calc(50% - 60px); left: calc(50% - 60px); &.show { display: flex !important; } } li { -webkit-transform: translate3d(0,0,0); transform: translate3d(0,0,0); transition: 1s ease; } { position: absolute; width: 120px; height: 120px; background: rgba(white, 0.9); text-align: center; align-items: center; justify-content: center; border-radius: 120px; display: none; text-decoration: none; color: #333; transition: 1s ease; box-shadow: 0 0 15px #222; font-family: "segoe ui"; font-weight: 200; font-size: 16px; } .selected { background: rgba(#333, 0.9); display: flex; top: calc(50% - 60px); left: calc(50% - 60px); color: #f1f1f1; box-shadow: 0 0 10px #f1f1f1; + ul { @for $i 1 through $sub-menus { > li:nth-child(#{$i}) { $angle: 360deg / $sub-menus * $i; -webkit-transform: rotate($angle) translatex(100px); transform: rotate($angle) translatex(100px); > { -webkit-transform: rotate(0 - $angle); transform: rotate(0 - $angle); } } } > li > { display: flex } } } }
javascript:
var buttons = document.queryselectorall(".radmenu a"); (var i=0, l=buttons.length; i<l; i++) { var button = buttons[i]; button.onclick = setselected; } function setselected(e) { if (this.classlist.contains("selected")) { this.classlist.remove("selected"); if (!this.parentnode.classlist.contains("radmenu")) { this.parentnode.parentnode.parentnode.queryselector("a").classlist.add("selected") } else { this.classlist.add("show"); } } else { this.classlist.add("selected"); if (!this.parentnode.classlist.contains("radmenu")) { this.parentnode.parentnode.parentnode.queryselector("a").classlist.remove("selected") } else { this.classlist.remove("show"); } } return false; }
just modify javascript code following,
function setselected(e) { if(this.getattribute("href") == "#"){ if (this.classlist.contains("selected")) { this.classlist.remove("selected"); if (!this.parentnode.classlist.contains("radmenu")) { this.parentnode.parentnode.parentnode.queryselector("a").classlist.add("selected") } else { this.classlist.add("show"); } } else { this.classlist.add("selected"); if (!this.parentnode.classlist.contains("radmenu")) { this.parentnode.parentnode.parentnode.queryselector("a").classlist.remove("selected") } else { this.classlist.remove("show"); } } return false; } else{ return true; } }
basically return false;
preventing page perform default action of going assigned href
.
Comments
Post a Comment