I'm trying to get mmenu to display in normal document flow when above a certain screen width, and below that width display as it does out of the box. I came across an answer where "cloning" was mentioned, though I'm not sure what this entails (is it just duplicating the menu with a different ID?)... I have a project with a 15 page site that this would be perfect for, if I could get it working as I'd like! Any help would be greatly appreciated!
I've tried wrapping the function like so (my jQuery/javascript is most definitely not my strong suit!):
$(document).ready(function($) {
if($(window).width() < 768) {
$("#menu").mmenu();
}
});
HTML:
<nav id="menu">
<ul>
<li class="Selected">ONE</li>
<li>TWO</li>
<li>THREE</li>
</ul>
</nav>
Creating a clone (and yes, changing its ID) gives you two NAVs with the same HTML inside it.
Fire the plugin on the first NAV and use CSS and media queries to show it in the mobile site. Again use CSS and media queries to hide it in the desktop site.
Vice versa use CSS and media queries to hide the first NAV in the mobile site and show it in the desktop site.
Note that the mmenu plugin has a build in option for cloning the menu that will automatically prepend all ID's in the menu with "mm-":
$("#menu").mmenu({
clone: true
});
Related
I know this is a very common problem, but I have spent ~two days crawling the forums, trying fixes, can't seem to find the answer.
I have a standard bootstrap setup that uses some parallax scrolling. I have a navbar fixed to the bottom of the page. Each <li> is shaped like a circle, and inside the <li> is an <a> tag. Each 'circular' <li> is linked to an anchor tag on the page in order to provide navigation around the page. This is a one-page template set up.
Here is a fiddle:
https://jsfiddle.net/k8g3qydw/1/
I have the bootstrap.css and .js files properly enqueued, I added data-target=".scrollspy" data-spy="scroll" data-offset="0"
to the body tag and added the class .scrollspy to the parent element of my <ul> like so:
<div class="scrollspy board-inner">
<ul class="nav nav-tabs" id="myTab">
<div class="liner"></div>
<li class="nav-item active">
So, I am pretty confused as to what to do!
Any help is much appreciated!
There are multiple mistakes in your code.
You should use one method to add Bootstrap ScrollSpy to your page, not both:
via Data Attributes or JavaScript. So you should delete your body attributes or javasript line $('body').scrollSpy({...});
ID attribute must be unique to the whole document. You have repeated IDs on page. And.. In wrong place. On working fiddle #spy was assigned to nav wrapper, since it is the one which is being spied.
Navbar links should point to "resolvable id targets" instead of <a name="service">. You should use <a id="service">.
And also make sure that bootstrap.min.js is included after jQuery in your document. Since jQuery is required for Bootstrap, not other way.
Here is a working JSFiddle
I am not really into all those coding terms, so I am having some difficulties to find answer to my problem. I want to create a single site menu. So if i press on a list item the browser should open an other content but on the same page. I tried using css with targets but everytime i click a new target the tagets will overlap and the old content will not disappear. I tried using Javascript with innerHTML but in javascript i need to write the whole page in a single line (.innerHTML ='websitecode') this will create a horrible overview.
Is there any other possibility to create something like this? Maybe with the require() / involve() function in php?
Thank you
From your question, what I understood is you want menu navigation without loading the content again.
`http://codepen.io/ArslanRafique/pen/raZybL`
Above is the snippet, I recently developed, simple menu navigation by using simple CSS and HTML. You can achieve simple menu navigation by using HTML label and can swap your views accordingly.
Please have a look at shared snippet, hope it will help you.
Sounds like you would like to create a single page web application:
There are many great javascript frameworks for this, try angular.
https://www.airpair.com/angularjs/building-angularjs-app-tutorial
Put your menu in the header file, and the content you want to replace in to views.
Or use angular UI-router https://github.com/angular-ui/ui-router/wiki
There are few possibilities to achieve your goal.
The simple and not so elegant one would be to generate the complete content and set anchors on the page. From the menu the user can call the anchors and will be brought to a desired part of the page. Example:
<!-- Menu -->
<ul>
<li>About us</li>
<li>Products</li>
</ul>
<!-- Page contents -->
<div id="aboutus">This is about us.</div>
<div id="products">Our products.</div>
More elegant, sophisticated and professional approach would be creating a SPA (single page application). It would include some techniques like AJAX, where you can load (or remove) contents on the page without refreshing.
There are many modern JS frameworks that can help you, for example AngularJS, ReactJS, etc.
Wikipedia offers also more information on SPA:
https://en.wikipedia.org/wiki/Single-page_application
So Arlan's version looks a lot prettier, but you can also use javaScript with divs that you can hide or display with functions. You can format the divs in your css with whatever you want. May get a little clunky if you have a long menu...
<div id="divOne">This will show some text</div>
<div id="divTwo"><p>This will show even more text</p><p>I may even format it differently</p>
</div>
<div id="divThree">This shows text that is different from the other two</div>
var formatOne = document.getElementById("button1"); //create handle for first button
formatOne.onclick = function() { //add functionality
document.getElementById("divOne").style.display = "block";
document.getElementById("divTwo").style.display = "none";
document.getElementById("divThree").style.display = "none";
}
Jsfiddle to show the functionality.
https://jsfiddle.net/lattivalidus/s7a9dLe7/
This question already has answers here:
Scroll to an element with jQuery
(32 answers)
Closed 9 years ago.
Hello am having a great problem scrolling the page to a specific element on page using jquery or javascript.
I've tried many ways of doing it but i failed in all of them. the website is implemented using the framework library called curtain.js https://github.com/victa/curtain.js.
The ways I have tried include:
1)https://developer.mozilla.org/en-US/docs/Web/API/element.scrollIntoView?redirectlocale=en-US&redirectslug=DOM%2Felement.scrollIntoView
2)How to go to a specific element on page?
3) I even tried the simplest way using anchor tags but nothing happens.
the only way that worked was scrollTop() as you can see from other links on the page. Unfortunately this doesn't work for me since this fails on different screen sizes.
you can see example of the site at http://pagota.herobo.com
Thanks !
UPDATE
Try this one, if you want a menu and menu links to specific page. It will scroll to your page with curtain effect.
DEMO http://jsfiddle.net/yeyene/mCytP/2/
Add menu outside of ol, then add links with your li page id in href.
<div id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Portfolio</li>
<li>Programs</li>
</ul>
</div>
I am currently building my personal portfolio and, not having a lot of practical knowledge in javascript, but having gone through a lot a tutorials, I decided to try to implement something I saw elsewhere: A detachable navigation.
Using this site, http://code.stephenmorley.org/javascript/detachable-navigation/, as a reference I set about creating my detaching navigation; however, something went horribly wrong.
For one, the header will automatically align to the left rather than returning to its default position.
Second, although you can't yet see it implemented, I wanted the social icons to show up in the navigation once they were scrolled past using an animation. That bit of code was so convoluted that I scrapped it.
Any pointers would be greatly appreciated.
Why not just use Bootstrap? It has this built in already: http://twitter.github.com/bootstrap/components.html#navbar
Download bootstrap: http://twitter.github.com/bootstrap/assets/bootstrap.zip
Add the bootsrap Javascript and CSS to your page.
In your HTML, add the following DIV:
You can change the div to fit your needs.
<div class="navbar navbar-fixed-top">
<li class="active">
Home
</li>
<li>Link</li>
<li>Link</li>
</div>
In xhtml I usually nest lists, close the tag then begin a new before the closing tag. This technique makes a the list structure clear when rendered without any css and it's a convenient structure for applying JS to.
Today I come up against a problem nesting links in a html5 document:
<header>
<nav>
A link
<a href="#">A link
<ul>
<li>nested link</li>
<li>nested link</li>
<li>nested link</li>
</ul>
</a>
</nav>
</header>
Which doesn't work. The nested list is nested in another a tag.
So a technique I used regularly in xhtml doesn't work in html5. My question is what do you do in the situation where you want to create a flyout menu? Is there a technique I can use in html5 to make it as easy as it is in xhtml? I know I can create this flyout menu without nested links but I liked the conciseness of the old method.
Build your menu structure in nested lists, and have the first element in every list be a link. Works just fine and you can make it look right in CSS.
I never want to make a flyout menu, but if a client cannot be convinced otherwise then:
The list of links at the top level would be represented as a list, not a bunch of anchors directly under the nav element
I would structure the DOM so a submenu would be represented as a list that appeared after a link, and not inside it.
I would use JavaScript to handle the opening/closing since :hover is inadequate as it:
doesn't work with keyboard access or
allow time to pass after the point leaves the menu before closing it (it is hard not to wobble across the edges for some people, e.g. those with arthritis)