how to make responsive sticky navbar working in desktop using uikit
here is what i have tried
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div uk-sticky="sel-target: .uk-navbar-container; cls-active: uk-navbar-sticky; bottom: #transparent-sticky-navbar" style="background-color: rgba(0,0,0,.4)">
<nav class="uk-navbar-container uk-navbar-transparent uk-height-match" uk-navbar style="position: relative; z-index: 980;height: 77px;">
<div class="uk-navbar-center">
<ul class="uk-navbar-nav">
<li class="uk-active">Active</li>
<li>
Parent
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<li class="uk-active">Active</li>
<li>Item</li>
<li>Item</li>
</ul>
</div>
</li>
<li>Item</li>
</ul>
</div>
</nav>
</div>
the navbar is working on all display views but i don't want it to work on tablet & mobile view
how can i achieve that ?
You can make a listener for window resize and when the window width is as a mobile size, hide your navbar, I made it once like this in your parent component :
data: function() {
return {
windowWidth: 0,
}
},
mounted() {
this.$nextTick(function() {
window.addEventListener('resize', this.getWindowWidth);
//Init
this.getWindowWidth()
})
},
methods: {
getWindowWidth(event) {
this.windowWidth = document.documentElement.clientWidth;
},
},
beforeDestroy() {
window.removeEventListener('resize', this.getWindowWidth);
}
And in your template for example (pseudo code):
<template>
<navbar v-if="windowWidth > 800px"></navbar>
</template>
Hope it helps
Related
I made a hamburger menu, and when I click on the links it closes it. Also has a logo which disappears when I click on the hamburger button.
The webpage has a mobile and a desktop computer version that doesn't have a hamburger menu.
But I have a problem. On the Desktop version, if I click on the links the Logo disappears as well.
I know that it does it because the hamburger-close-after-click event triggers it.
But I don't know how I could change it to make it work well.
jQuery Code
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const links = document.querySelectorAll('.nav-links li');
var mylogo = document.getElementById("myLogo");
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
links.forEach(link =>{
link.classList.toggle("fade");
});
});
//logo-toggle
$(document).ready(function(){
$('.hamburger').click(function() {
$('.logo-container').toggle().delay( 800 );
});
});
// hamburger-close-after-click event
$( '.nav-links li a' ).on("click", function(){
$('#hamburgerID').click();
});
HTML Code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<nav>
<div class="hamburger" id="hamburgerID">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
</nav>
<header class="header" id="myHeader">
<div class="logo-container" id="myLogo">
<img src="./img/logo.png" alt="logo"/>
</div>
<nav>
<ul class="nav-links">
<li><a class="nav-link" href="#details">DETAILS</a></li>
<li><a class="nav-link" href="#description">DESCRIPTION</a></li>
<li><a class="nav-link" href="#aboutus">ABOUT US</a></li>
</ul>
</nav>
The problem with pictures
[
You can use JQuery.toggleClass() to add and remove CSS classes, instead of using JQuery.toggle(), e.g.:
$('.hamburger').click(function() {
$('.logo-container').toggleClass('open');
})
And then, in the CSS file, define the visibility depending on the screen size, e.g.:
.logo-container { display: 'none' }
.logo-container.open { display: 'block' }
#media (min-width: 1025px) {
.logo-container { display: 'block' }
}
(Note: You will want to decide yourself how to identify the appropriate size to hide and show the elements. See also e.g.: how-to-target-desktop-tablet-and-mobile)
I have a web page with a navbar and map div. Everything is great but there is a scroll bar on the page and you must scroll to see the full map. I would like the full map div to show up on the screen without any scrolling. How do I accomplish this? Thank you
HTML:
<nav class="default" role="navigation">
<div class="nav-wrapper">
NTN Trails
<a href="#" data-activates="mobile-demo" class="button-collapse show-
on-large"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
</ul>
<ul class="side-nav" id="mobile-demo">
<li>Login</li>
<li>Sign up</li>
</ul>
</div>
</nav>
<script>
$('.button-collapse').sideNav({
menuWidth: 240, // Default is 240
edge: 'left', // Choose the horizontal origin
closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor
}
);
</script>
<!--put your initial page content here-->
<div id="map"></div>
CSS:
html, body, #map {
height: 100%;
width: 100%;
}
#media only screen and (min-width: 993px){
nav a.button-collapse {
display: block;
}
}
I am trying to have a submenu dropdown inside a dropdown, using MaterializeCSS framework. I tried with the following code, but it didn't work.
<!-- this the main dropdown -->
<ul id="MainDropDown" class="dropdown-content">
<li>Dropdown1<span class="right caret">►</span></li>
<li>Dropdown2<span class="right caret">►</span></li>
<li>Dropdown3<span class="right scaret">►</span></li>
</ul>
<ul id="drop1" class="dropdown-content">
<li>Create</li>
</ul>
<ul id="drop2" class="dropdown-content">
<li>Create</li>
<li>Update</li>
</ul>
<ul id="drop3" class="dropdown-content">
<li>Create</li>
</ul>
I was having the same issue myself.
Turns out it's as simple as nesting another dropdown link,
setting an appropriate gutter, and making sure the overflow of
dropdown-content is set to visible.
Here is a link to the modified jsfiddle linked in Nested dropdowns in materialize
https://jsfiddle.net/fb0c6b5b/
$('.dropdown-button2').dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: false, // Does not change width of dropdown to that of the activator
hover: true, // Activate on hover
gutter: ($('.dropdown-content').width()*3)/2.5 + 5, // Spacing from edge
belowOrigin: false, // Displays dropdown below the button
alignment: 'left' // Displays dropdown with edge aligned to the left of button
}
);
.dropdown-content{
overflow: visible !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class='dropdown-button btn' href='#' data-activates='dropdown1' data-beloworigin="true">Drop Me!</a>
<ul id='dropdown1' class='dropdown-content'>
<li>two</li>
<li class="divider"></li>
<li>three</li>
<li><a class='dropdown-button2 d' href='#' data-activates='dropdown2' data-hover="hover" data-alignment="left">Drop Me!</a></li>
</ul>
<ul id='dropdown2' class='dropdown-content'>
<li>one</li>
<li>two</li>
<li class="divider"></li>
<li>three</li>
</ul>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
I tried it here but my was aligned on the same line from the dropdown, then did it and it worked:
.dropdown-content {
overflow-y: visible;
}
.dropdown-content .dropdown-content {
margin-left: 100%;
}
Based on the answer from #LibanH and updated for version v1.0.0, you need some change.
constrain_width must be replaced by constrainWidth and gutter is no longer an option.
In order to display the nested dropdown at the good position, we need to get the height of the selected item in first dropdown and set position with CSS
$('.dropdown-button').dropdown({
onOpenStart: function() {
var selectedItem = $(this).find('.selected');
$('#dropdown2').css('top', selectedItem.outerHeight() + "px");
}
});
$('.dropdown-button2').dropdown({
constrainWidth: false //change
hover: true,
alignment: 'left'
}
);
and add some CSS
#dropdown2 {
position: absolute;
left: 100%;
}
I have a responsive nav bar. When the screen size decreases a little, the last li goes to the next line under other li's. What should I do to fix it so it doesn't move to the next line under the other menu elements?
HTML codes:
<nav class="cd-main-nav-wrapper mainNav">
<ul class="cd-main-nav">
<li style="margin-right:none;" class="logoNavPos">
<a href="index.html">
<img src="pic/logo1.jpg" alt="" class="desktopLogo">
</a>
</li>
<li class="current_page_item">
خانه </li>
<li>مزایای بیمه عمر</li>
<li>بیمه عمر و سرمایه گذاری</li>
<li>پرسش های متداول</li>
<li>درباره ما</li>
<li style="display:none;" class="mobileSwLang">
English version</li>
</ul>
</nav>
https://jsfiddle.net/MelodyHajian/4ntL3m9o/
give me advices plz.
jquery may help
here is a jsfiddle i played with......
$(window).resize(function() {
var windowsize = $(window).width();
if (windowsize > 767) {
$('.nav').show();
} else {
$('.nav').hide();
$('.toggle').removeClass('open');
}
})
$('.toggle').click(function(event) {
$(this).toggleClass('open');
if ($(this).hasClass('open')) {
$('.nav').show();
} else {
$('.nav').hide();
}
})
http://jsfiddle.net/GlynneT/2pv9pkb0/
I have created a responsive menu that can opens and collabses when i push the open menu.
But the problem is that when i resize the screen it is auto opened when it hits 680 px or lower and if i then collapse the menu when i'm mobile size and try to resize it to desktop again(over 680px) the menu stays hidden.
html code
<img src="assets/img/nav-icon.png" alt="Menu">
<div class="bar">
<div class="lang">
<div class="langDK"></div>
<div class="langUK"></div>
</div>
<ul class="navigation">
<img src="assets/img/logo.png" alt="">
<li class="item">Home</li>
<li class="item">Products</li>
<li class="item">Work</li>
<li class="item">About</li>
<li class="item">Contact</li>
</ul>
</div>
jquery
$(function(){
var pull = $('#pull');
menu = $('.bar .item');
w = $(window).width();
if(w > 680 ) {
menu.show()
}
if(w < 680){
menu.hide();
}
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
});
i also have some css and media querys but dont think the problem lies there.
Set up the event listener for the window's resize:
$(window).on('resize', function(){
var menu = $('.bar .item');
var w = $(window).width();
if(w >= 680 ) {
menu.show()
}else{
menu.hide();
}
})
If you'd like to hide the li items by default, add the CSS class as below:
li.item {display:none;}
try this one
$(function() {
var pull = $('#pull');
menu = $('.navigation .dropdown');
menuHeight = menu.height();
$(pull).on('click', function(e) {
e.preventDefault();
menu.slideToggle();
});
$(window).resize(function(){
var w = $(window).width();
if(w > 320 && menu.is(':hidden')) {
menu.removeAttr('style');
}
});
});
Html
<div class="navigation">
<ul class="nav pull-right group dropdown">
<li class="nav-line-image"></li>
<li>Home</li>
<li>About Us</li>
<li>Design Gallery</li>
<li>Designer Collection</li>
<li>Silver Collection</li>
<li>Promotion/Events</li>
<li class="active">Branch Details</li>
<li>Contact Us</li>
<li class="nav-line-image"></li>
</ul>
</div><!--navigation end-->
css for mobile and tabs
.nav{
display : none;
position: relative;
}
#pull {
position: absolute;
display : block;
width : 17px;
height : 20px;
color : #5a504c;
margin : 15px 0 0 20px;
background : #ccc;
text-decoration :none;
}