I want to select a tab on clicking a link. I tried using different online available solutions (including $('ul.tabs').tabs('select_tab', 'tab_id');) but none seems to be work with current materialize version. The official documentation for materialize states to do the initialization using var instance = M.Tabs.init(el, options); instance.select('tab_id'); but none of the methods seem to work correctly with current version or has been clearly specified w.r.t Materialize Tabs.
Any help is greatly appreciated. Below is the code snippet along with jsfiddle link,
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
<!--
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
-->
<script>
$(document).ready(function() {
$('ul.tabs').tabs();
$("#btnContinue").click(function() {
$('ul.tabs').tabs('select_tab', 'test2');
});
});
/* var instance = new M.Tabs.init(el, options);
function check_active(){
var instance = M.Tabs.getInstance(elem);
instance.select('test2');
} */
</script>
</head>
<body>
<div class="col s12">
<ul class="tabs">
<li class="tab col s4">tab1
</li>
<li class="tab col s4">tab2
</li>
<li class="tab col s4">tab3
</li>
</ul>
</div>
<div id='test1' class="col s12">
<!--<a id="btnContinue" href='#test2' onclick="check_active();">continue</a>-->
<a id="btnContinue" href='#test2'>continue</a>
</div>
<div id='test2' class="col s12"></div>
</body>
</html>
JSFiddle Link for the same: https://jsfiddle.net/chirag_cyber/6evpqcfb/6/
You should change
$('ul.tabs').tabs('select_tab', 'test2');
to :
$('ul.tabs').tabs('select', 'test2');
select shows tab content that corresponds to the tab with the id. JSFiddle
I have implemented the blueimp carousel (2.22.0) on a gallery page. It works fine and is displaying the images in the carousel. But it is also showing all the images below the carousel in a quasi light box style. This is my code.
<link href="~/Content/Css/blueimp-gallery.min.css" rel="stylesheet" />
<div class="page-header">
<h2>#Model.Name</h2>
</div>
<!-- The Gallery as inline carousel, can be positioned anywhere on the page -->
<div id="blueimp-gallery-carousel" class="blueimp-gallery blueimp-gallery-carousel">
<div class="slides"></div>
<h3 class="title"></h3>
<a class="prev">‹</a>
<a class="next">›</a>
<a class="play-pause"></a>
<ol class="indicator"></ol>
</div>
<div id="links">
#foreach (GalleryViewItemVM item in Model.Images)
{
<a href="#item.ImagePath" title="">
<img src="#item.ThumbPath" alt="">
</a>
}
</div>
<script src="~/Scripts/blueimp-gallery.min.js"></script>
<script>
blueimp.Gallery(
document.getElementById('links').getElementsByTagName('a'),
{
container: '#blueimp-gallery-carousel',
carousel: true
}
);
</script>
For completeness I am using razor and bootstrap 3 although I don't think this relevant.
The <img> tag within the <a> tag is unneccesary and is causing the unwanted behavior.
I'm new on bulma css http://bulma.io/
I'm trying to use hamburger menu for mobile user.
I just followed instruction on this page: http://bulma.io/documentation/components/nav/
But it doesn't work. What should I add ?
Actually, I can see hamburger menu, but it doesn't work when I am click it.
Thank you.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>test</title>
<link rel="stylesheet" href="css/bulma.min.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<section class="hero is-fullheight is-primary is-bold">
<!-- Hero header: will stick at the top -->
<div class="hero-head">
<header class="nav">
<div class="container">
<div class="nav-left">
<a class="nav-item" href="/">
<img src="img/logo.png" alt="Logo">
</a>
</div>
<span class="nav-toggle">
<span></span>
<span></span>
<span></span>
</span>
<div class="nav-right nav-menu">
<a class="nav-item" href="/about">
About
</a>
<a class="nav-item" href="/path">
Path
</a>
<a class="nav-item" href="/blog">
Blog
</a>
</div>
</div>
</header>
</div>
<!-- Hero content: will be in the middle -->
<div class="hero-body">
<div class="container has-text-centered">
</div>
</div>
</section>
</body>
</html>
This solution uses Vue.js to toggle the bulma nav component when viewing on mobile. I hope this helps others that are looking for an alternative solution.
JS
First, I add the cdn for Vue.js which can be found here https://unpkg.com/vue, and include an instance of Vue in the javascript.
new Vue({
el: '#app',
data: {
showNav: false
}
});
HTML
a. Wrap the nav section with the element "app" to make it reactive (this maps to the "el" property of the Vue instance).
<div id="app"> ... </div>
b. Update .navbar-burger using the v-on: directive to listen for the click event and toggle the data property showNav.
<div class="navbar-burger" v-on:click="showNav = !showNav" v-bind:class="{ 'is-active' : showNav }">
c. Update .navbar-menu using the v-bind: directive to reactively update the class attribute with the result of the showNav property.
<div class="navbar-menu" v-bind:class="{ 'is-active' : showNav }">
Solution
I've included the entire solution in this jsfiddle
This may be an issue with the example given in the docs, I was able to get it working by adding ids to the .nav-toggle and .nav-menu.
<span id="nav-toggle" class="nav-toggle"> and <div id='nav-menu' class="nav-right nav-menu">
jsfiddle here.
So to get the example working, you'd have to add 'id's to the respective elements. I'd recommend deep diving into the docs though
(function() {
var burger = document.querySelector('.nav-toggle');
var menu = document.querySelector('.nav-menu');
burger.addEventListener('click', function() {
burger.classList.toggle('is-active');
menu.classList.toggle('is-active');
});
})();
You can get it to work without using jquery or bulma.js. Just simply use your own javascript to add is-active to nav-menu class on click on nav-toggle.
nav-menu is collapsed.
nav-menu is-active is expanded.
I thought someome might be looking for a solution without jquery so there will be everything in one place.
To make the toggle click event work, just add the below js code. You may create a JS folder, then bulma.js file.
// source: https://gist.github.com/Bradcomp/a9ef2ef322a8e8017443b626208999c1
(function () {
var burger = document.querySelector('.burger');
var menu = document.querySelector('#' + burger.dataset.target);
burger.addEventListener('click', function () {
burger.classList.toggle('is-active');
menu.classList.toggle('is-active');
});
})();
At the end of your html page add the script.
ex:
<script async type="text/javascript" src="./js/bulma.js"></script>
There is an easier way! Before I get to that, it looks like there are a few problems with your Html.
First issue. You don't have the navbar structure set up like the documentation suggests. If you replace the nav-left with navbar-brand it will take care of some of your Html for you. In your code example, you have your logo as a nav-item inside of a nav-left. navbar-brand does exactly that. What you've done here may work but, I'm not sure exactly what that would do. From the documentation:
"navbar-brand the left side, always visible, which usually contains the logo and optionally some links or icons"
So if you take that out to the level of the of the container and within that, you can just put your logo inside the first navbar-item. Next thing is to pull the 'navbar-burgerinside of thenavbar-brand`.
"The navbar-burger is a hamburger menu that only appears on mobile. It has to appear as the last child of navbar-brand."
Once that is set up you'll want to put the menu items you wish to collapse inside of the navbar-menu. This container should be a sibling of the navbar-brand so they should be on the same level together. So your code (within your container div) should look something LIKE SO:
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="/">
<img src="../assets/icon.png" alt="something">
</a>
<div class="navbar-burger burger" data-target="Options">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="navbar-menu" id="Options">
<div class="navbar-end">
<a class="nav-item" href="/about">About</a>
<a class="nav-item" href="/path">Path</a>
<a class="nav-item" href="/blog">Blog</a>
</div>
</div>
</nav>
The final piece to the puzzle is: you gotta set the data-target of your burger to the the id of the navbar-menu. It's not very clear that's what they are talking about in the docs. Whatever the case, after you make those changes, the javascript code from the documentation should work!
I realize that this question was asked many moons ago but I hope this can help SOMEONE.
Bulma Docs
http://bulma.io/documentation/components/navbar/
My simple but functional answer:
function toggleBurger() {
var burger = $('.burger');
var menu = $('.navbar-menu');
burger.toggleClass('is-active');
menu.toggleClass('is-active');
}
And in the burger tag:
<div class="navbar-burger burger" data-target="navMenu" onclick="toggleBurger()">
<span></span>
<span></span>
<span></span>
</div>
Here is an angular solution:
template - button (notice the last two lines)
<a
role="button"
class="navbar-burger burger"
aria-label="menu"
aria-expanded="false"
data-target="navbarBasicExample"
[class.is-active]="showBurgerMenu"
(click)="showBurgerMenu = !showBurgerMenu">
template - menu (notice the last line)
<div
id="navbarBasicExample"
class="navbar-menu"
[class.is-active]="showBurgerMenu">
component (notice the showBurgerMenu property)
import { Component, OnInit } from '#angular/core';
#Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.sass']
})
export class NavbarComponent {
showBurgerMenu: boolean;
constructor() {}
}
The bulma package does not provide any javascript. So you have to write it yourself. But you do not need anything fancy. Just make the id of toggled element and the data-target of the burger be the same. Something like this:
<a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<div class="navbar-menu" id="navMenu">
<!-- navbar-start, navbar-end... -->
</div>
And add this javascript snippet into end of your file(note: you do not have to change anything):
<script>
document.addEventListener('DOMContentLoaded', () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
});
</script>
And that is it! It works!
These codeblocks has been taken from documentation: https://bulma.io/documentation/components/navbar/#navbar-burger
you can also make it work with an inline onclick
<a role="button" onclick="this.classList.toggle('is-active');document.querySelector('#'+this.dataset.target).classList.toggle('is-active');" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="efpnavbar">
I had the same problem with Vue.js and I solved it like this :
<span class="navbar-burger burger" data-target="navbarMenu" #click="show()">
<span></span>
<span></span>
<span></span>
</span>
</div>
<div id="navbarMenu" class="navbar-menu">
<div class="navbar-end">
<div class="tabs is-right">
<ul>
<li><a>Home</a></li>
<li>Examples</li>
<li>Features</li>
<li>Team</li>
<li>Help</li>
</ul>
</div>
</div>
</div> </span>
then I added this code in methods section :
methods:{
show()
{
var burger = document.querySelector('.burger');
var menu = document.querySelector('.navbar-menu');
burger.classList.toggle('is-active');
menu.classList.toggle('is-active');
}}
I hope this code helps someone .
If you use SCSS and i.e. purge-css for your project, make sure the .is-active class is not stripped out by your css-purging...
For me then the vanilla example worked:
JS:
document.addEventListener("DOMContentLoaded", () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(
document.querySelectorAll(".navbar-burger"),
0
);
// Add a click event on each of them
$navbarBurgers.forEach((el) => {
el.addEventListener("click", () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle("is-active");
$target.classList.toggle("is-active");
});
});
});
and HTML:
<nav class="navbar headnavi is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="{{ site.url }}">
<span class="is-size-3 is-size-5-mobile has-text-weight-semibold ml-2">{{ site.name }}</span>
</a>
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="top">
<span aria-hidden="true" class="nav-toggle" ></span>
<span aria-hidden="true" class="nav-toggle" ></span>
<span aria-hidden="true" class="nav-toggle" ></span>
</a>
</div>
<div id="top" class="navbar-menu">
<div class="navbar-start">
</div>
<div class="navbar-end">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="/">
More
</a>
<div class="navbar-dropdown is-right">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Jobs
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider">
<a class="navbar-item">
Report an issue
</a>
</div>
</div>
<div class="navbar-item">
<div class="buttons">
</div>
</div>
</div>
</div>
</nav>
I'm trying the tab example from semantic ui but I can't make it work. the tabs don't change. did I forget to include something?
$(function() {
$('.menu .item').tab();
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.js"></script>
<div class="ui top attached tabular menu">
<a class="item active" data-tab="first">First</a>
<a class="item" data-tab="second">Second</a>
<a class="item" data-tab="third">Third</a>
</div>
<div class="ui bottom attached tab segment active" data-tab="first">
First
</div>
<div class="ui bottom attached tab segment" data-tab="second">
Second
</div>
<div class="ui bottom attached tab segment" data-tab="third">
Third
</div>
I beleive you need to call this
$(function () {
$('.menu .item').tab();
});
to make your tabs works.
And semantic-ui have great documentation you should look there.
I'm having a bit o dificulty making this work.
This is my first website, I'm using Zurb and finding it good so far.
I'm trying to implement a responsive nav, but it isn't working. The one I'm trying is this one: http://responsive-nav.com/#instructions. I made everything they ask to, but it still don't work. It's the same as not adding code at all to the website.
Some of the nav's code, if it helps:
<div class="row" id="row-top">
<div class="large-4 small-8 columns logo">
<img src="img/logo.png" alt="Laboratório Morales">
</div> <!-- logo -->
<div class="large-8 small-12 columns nav">
<ul class="inline-list menu-principal">
<li>Laboratório</li>
<li>Exames</li>
<li>Convênios</li>
<li>Estrutura</li>
</ul> <!-- menu-principal -->
</div> <!-- menu-principal div -->
</div> <!-- row topo -->
Calling in the head, and bottom of body:
<link rel="stylesheet" href="css/responsive-nav.css"> <!-- responsive nav -->
<script src="js/responsive-nav.js"></script> <!-- responsive nav -->
<script>
var navigation = responsiveNav("#nav");
</script> <!-- responsive nav -->
Hm ... you are passing an id #nav. But you put nav in the class property. It should be
<div class="large-8 small-12 columns" id="nav">
Isn't it?