I'm working on my portfolio website, but have a problem with my navigation overlay. When I open it, it works just fine. When I click on an item in the overlay it does navigate to it on the page, as it navigates to a part of the home page, but doesn't close the navigation overlay. Clicking on the X does still close it so there is no problem there. It jst doesn't close after clicking on a nav item
I'm using vanilla javascript for it with toggleClass, but I cant figure out why it doesn't close.I have tried removeClass aswell, but no luck there
$(document).ready(function() {
$('.menu-toggler').on('click', function() {
$(this).toggleClass('open').show;
$('.top-nav').toggleClass('open').show;
});
});
.top-nav {
width: 100%;
height: 100vh;
position: fixed;
top: -100vh;
z-index: 50;
background-color: #16162d;
border-bottom-right-radius: 100%;
border-bottom-left-radius: 100%;
transition: all 650ms cubic-bezier(1, 0, 0, 1);
}
.nav-list {
list-style: none;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
li {
margin: 0 2rem;
}
.nav-link {
font-family: 'The Historia Demo', sans-serif;
font-size: 5rem;
padding: 1rem;
}
.nav-link:hover,
.nav-link:focus {
background: linear-gradient(to top, #00ffde, #0003fd);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.top-nav.open {
top: 0;
border-radius: initial;
}
.menu-toggler {
position: absolute;
top: 5rem;
right: 5rem;
width: 5rem;
height: 4rem;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
z-index: 1500;
transition: transform 650ms ease-out;
}
.menu-toggler.open {
transform: rotate(-45deg);
}
.bar {
background: linear-gradient(to right, #00e4ff, #0003fd);
width: 100%;
height: 4px;
border-radius: .8rem;
}
.bar.half {
width: 50%;
}
.bar.start {
transform-origin: right;
transition: transform 650ms cubic-bezier(0.54, -0.81, 0.57, 0.57);
}
.open .bar.start {
transform: rotate(-450deg) translateX(.8rem);
}
.bar.end {
align-self: flex-end;
transform-origin: left;
transition: transform 650ms cubic-bezier(0.54, -0.81, 0.57, 0.57);
}
.open .bar.end {
transform: rotate(-450deg) translateX(-.8rem);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="menu-toggler">
<div class="bar half start"></div>
<div class="bar "></div>
<div class="bar half end"></div>
</div>
<nav class="top-nav">
<ul class="nav-list">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Portfolio</li>
<li>Experience</li>
<li>Contact</li>
</ul>
</nav>
For all the code here is my codepen
https://codepen.io/Triable/pen/BayqOWO
You need to add another event handler for click the .top-nav:
var $toggler = $('.menu-toggler');
var $topNav = $('.top-nav');
function toggle() {
$toggler.toggleClass('open');
$topNav.toggleClass('open');
}
$toggler.on('click', toggle);
$topNav.on('click', toggle);
.top-nav {
width: 100%;
height: 100vh;
position: fixed;
top: -100vh;
z-index: 50;
background-color: #16162d;
border-bottom-right-radius: 100%;
border-bottom-left-radius: 100%;
transition: all 650ms cubic-bezier(1, 0, 0, 1);
}
.nav-list {
list-style: none;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
li {
margin: 0 2rem;
}
.nav-link {
font-family: 'The Historia Demo', sans-serif;
font-size: 5rem;
padding: 1rem;
}
.nav-link:hover,
.nav-link:focus {
background: linear-gradient(to top, #00ffde, #0003fd);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.top-nav.open {
top: 0;
border-radius: initial;
}
.menu-toggler {
position: absolute;
top: 5rem;
right: 5rem;
width: 5rem;
height: 4rem;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
z-index: 1500;
transition: transform 650ms ease-out;
}
.menu-toggler.open {
transform: rotate(-45deg);
}
.bar {
background: linear-gradient(to right, #00e4ff, #0003fd);
width: 100%;
height: 4px;
border-radius: .8rem;
}
.bar.half {
width: 50%;
}
.bar.start {
transform-origin: right;
transition: transform 650ms cubic-bezier(0.54, -0.81, 0.57, 0.57);
}
.open .bar.start {
transform: rotate(-450deg) translateX(.8rem);
}
.bar.end {
align-self: flex-end;
transform-origin: left;
transition: transform 650ms cubic-bezier(0.54, -0.81, 0.57, 0.57);
}
.open .bar.end {
transform: rotate(-450deg) translateX(-.8rem);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="menu-toggler">
<div class="bar half start"></div>
<div class="bar "></div>
<div class="bar half end"></div>
</div>
<nav class="top-nav">
<ul class="nav-list">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Portfolio</li>
<li>Experience</li>
<li>Contact</li>
</ul>
</nav>
Related
I have a problem making the hamburger menu sticky. So the hamburger icon is in the corner when i scroll down, but the menu stays in the same position(at the top of the page), so I have to scroll back up again to look at it. I got the code from codepen, i tried adjusting the code, but didnt figure out how.
If you want to view where i got the code from here is the link, but it is not necessary in my opinion for i only removed code that wasnt related to the hamburger menu: https://codepen.io/CopyPasteLtd/pen/BaxQeGw
See the snippet below.
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#200;300;400&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
.container {
width: 100%;
height: 100vh;
/* background: linear-gradient(-45deg, #ee7752, #e73c7e);
background-size: 400% 400%; */
position: relative;
}
.nav-bar {
position: absolute;
background-color: #122;
top: 0;
left: -25rem;
height: 100vh;
width: 25rem;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
top: 2rem;
left: 2rem;
width: 4rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
}
.line {
width: 100%;
height: 4px;
border-radius: 5px;
background-color: #fff;
transition: 0.4s ease-out;
}
.toggle .line1 {
background-color: #c91919;
transform: scale(0.9) rotateZ(-45deg) translate(-6px, 4px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #c91919;
transform: scale(0.9) rotateZ(45deg) translate(-6px, -4px);
}
.toggle .toggle-menu {
background-color: white;
}
.nav-list {
list-style: none;
}
.nav-list-item {
text-align: center;
padding: 1rem 0;
}
.nav-link {
color: #fff;
font-size: 2.2rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="container">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Home</li>
<li class="nav-list-item">About</li>
<li class="nav-list-item">
Projects
</li>
<li class="nav-list-item">Clients</li>
<li class="nav-list-item">
Contact Me
</li>
</ul>
</nav>
</div>
Change .nav-bar { position: absolute; } to .nav-bar { position: fixed; }.
See the snippet below.
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#200;300;400&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
.container {
width: 100%;
height: 100vh;
/* background: linear-gradient(-45deg, #ee7752, #e73c7e);
background-size: 400% 400%; */
position: relative;
}
.nav-bar {
position: fixed;
background-color: #122;
left: -25rem;
height: 100vh;
width: 25rem;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: rgba(0, 0, 0, 0.2);
position: fixed;
top: 2rem;
left: 2rem;
width: 4rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
}
.line {
width: 100%;
height: 4px;
border-radius: 5px;
background-color: #fff;
transition: 0.4s ease-out;
}
.toggle .line1 {
background-color: #c91919;
transform: scale(0.9) rotateZ(-45deg) translate(-6px, 4px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #c91919;
transform: scale(0.9) rotateZ(45deg) translate(-6px, -4px);
}
.toggle .toggle-menu {
background-color: white;
}
.nav-list {
list-style: none;
}
.nav-list-item {
text-align: center;
padding: 1rem 0;
}
.nav-link {
color: #fff;
font-size: 2.2rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="container">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Home</li>
<li class="nav-list-item">About</li>
<li class="nav-list-item">
Projects
</li>
<li class="nav-list-item">Clients</li>
<li class="nav-list-item">
Contact Me
</li>
</ul>
</nav>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
I am new to coding and busy developing a navbar for a responsive site. When the screen is 100% the menu is visible, but as soon as the browser is dragged smaller it is responsive and the menu is colapsing with a hamburger icon (three stripes). I have attempted to trouble shoot but was unsuccessful thusfar. Any assistance will be appreaciated!
<!--Navbar-->
<nav class="navbar">
<div class="navbar__container">
NEXT
<div class="navbar__toggle" id="mobile-menu">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
<ul class="navbar__menu">
<li class="navbar__item">
Home
</li>
<li class="navbar__item">
Tech
</li>
<li class="navbar__item">
Products
</li>
<li class="navbar__btn">
Sign up
</li>
</ul>
</div>
Css:
#media screen and (max-width: 960px) {
.navbar__container {
display: flex;
justify-content: space-between;
height: 80px;
z-index: 1;
width: 100%;
max-width: 1300px;
padding: 0;
}
.navbar__menu {
display: grid;
grid-template-columns: auto;
margin: 0;
width: 100%;
position: absolute;
top: -1000px;
opacity: 0;
transition: all 0.5s ease;
height: 58vh;
z-index: -1;
background: #131313;
}
.navbar__menu:active {
background: #131313;
top: 100%;
opacity: 1;
transition: all 0.5s ease;
z-index: 99;
height: 58vh;
font-size: 1.6rem;
}
#navbar__logo {
padding-left: 25px;
}
.navbar__toggle .bar {
width: 25px;
height: 3px;
margin: 5px auto;
transition: all 0.3s ease-in-out;
background: #fff;
}
.navbar__item {
width: 100%;
}
.navbar__links {
text-align: center;
padding: 2rem;
width: 100%;
display: table;
}
#mobile-menu {
position: absolute;
top: 20%;
right: 5%;
transform: translate(5%, 20%);
}
.navbar__btn {
padding-bottom: 2rem;
}
.button {
display: flex;
justify-content: center;
align-items: center;
width: 80%;
height: 80px;
margin: 0;
}
.navbar__toggle .bar {
display: block;
cursor: pointer;
}
#mobile-menu.is-active .bar:nth-child(2) {
opacity: 0;
}
#mobile-menu.is-active .bar:nth-child(1) {
transform: translateY(8px) rotate(45deg);
}
#mobile-menu.is-active .bar:nth-child(3) {
transform: translateY(-8px) rotate(-45deg);
}
Java Script:
const menu = document.querySelector('#mobile-menu');
const menu = document.querySelector('#mobile-menu');
menu.addEventListener('click', function() {
menu.classList.toggle('is-active');
menuLinks.classList.toggle('active');
});
Okay so basically I have to do an internet site for school with HTML but only javascript animation, all the code work proprely but when I want to transform the three lines I use for my hamburger menu into a cross with a javascript animation nothing is happening and I really don't know why.
If someone can help me I will be really greatful as always, thanks for reading.
<!doctype html>
<head>
<meta charset="utf-8">
<title>California Hotel</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
.container{
width: 100%;
height: 100vh;
background-color: grey;
}
.navbar{
width: 300px;
height: 100%;
background-color: blanchedalmond;
position: fixed;
top: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10% 0 0 5%;
}
.hamburger-menu{
width: 35px;
height: 30px;
position: fixed;
top: 50px;
right: 50px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.line{
width: 100%;
height: 3px;
background-color: black;
}
.change .line-1{
transform: rotate(-45deg) translate(-8px,6px);
}
.change .line-2{
opacity: 0;
}
.change .line-3{
transform: rotate(45deg) translate(-8px,-6px);;
}
.nav-list{
text-align: right;
}
.nav-item{
list-style: none;
margin: 25px;
}
.nav-links{
text-decoration: none;
font-size: 20px;
color: rgb(22, 73, 73);
font-weight: 300;
letter-spacing: 1px;
text-transform: uppercase;
position: relative;
padding: 3px 0;
}
.nav-links::before,
.nav-links::after{
content: "";
width: 100%;
height: 2px;
background-color: orange;
position: absolute;
left: 0;
transform: scaleX(0);
transition: transform 0.5s;
}
.nav-links::after{
bottom: 0;
transform-origin: right;
}
.nav-links::before{
top: 0;
transform-origin: left;
}
.nav-links:hover::before,
.nav-links:hover::after{
transform: scaleX(1);
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar">
<div class="hamburger-menu">
<div class="line line-1"></div>
<div class="line line-2"></div>
<div class="line line-3"></div>
</div>
<ul class="nav-list">
<li class="nav-item">
A PROPOS
</li>
<li class="nav-item">
NOUS CONTACTER
</li>
<li class="nav-item">
NOS RESEAUX SOCIAUX
</li>
</ul>
</nav>
</div>
<script>
const menuIcon = document.querySelector(".hamburger-menu");
const navbar = document.querySelector(".nabar");
MenuIcon.addEventListener("click",() => {
navbar.classList.toggle(".change")});
</script>
</body>
</html>
here is your correct code :
missing ; and remove . before class in javascript code. good luck.
const MenuIcon = document.querySelector(".hamburger-menu");
const navbar = document.querySelector(".navbar");
MenuIcon.addEventListener("click", () => {
navbar.classList.toggle("change");
});
* {
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
.container {
width: 100%;
height: 100vh;
background-color: grey;
}
.navbar {
width: 300px;
height: 100%;
background-color: blanchedalmond;
position: fixed;
top: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10% 0 0 5%;
}
.hamburger-menu {
width: 35px;
height: 30px;
position: fixed;
top: 50px;
right: 50px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-around;
}
.line {
width: 100%;
height: 3px;
background-color: black;
}
.change .line-1 {
transform: rotate(-45deg) translate(-8px, 6px);
}
.change .line-2 {
opacity: 0;
}
.change .line-3 {
transform: rotate(45deg) translate(-8px, -6px);
;
}
.nav-list {
text-align: right;
}
.nav-item {
list-style: none;
margin: 25px;
}
.nav-links {
text-decoration: none;
font-size: 20px;
color: rgb(22, 73, 73);
font-weight: 300;
letter-spacing: 1px;
text-transform: uppercase;
position: relative;
padding: 3px 0;
}
.nav-links::before,
.nav-links::after {
content: "";
width: 100%;
height: 2px;
background-color: orange;
position: absolute;
left: 0;
transform: scaleX(0);
transition: transform 0.5s;
}
.nav-links::after {
bottom: 0;
transform-origin: right;
}
.nav-links::before {
top: 0;
transform-origin: left;
}
.nav-links:hover::before,
.nav-links:hover::after {
transform: scaleX(1);
}
<div class="container">
<nav class="navbar">
<div class="hamburger-menu">
<div class="line line-1"></div>
<div class="line line-2"></div>
<div class="line line-3"></div>
</div>
<ul class="nav-list">
<li class="nav-item">
A PROPOS
</li>
<li class="nav-item">
NOUS CONTACTER
</li>
<li class="nav-item">
NOS RESEAUX SOCIAUX
</li>
</ul>
</nav>
</div>
i'm very new on the javascript field and i have a big problem.
I worked on it the last 7 days and i can't find a solution.
I hope that anyone could tell me the code to solve this problem.
The following snippet show's my navigation. It work's fine on chrome, firefox but not on the IE11 - and it must worked on it.
It don't opened on IE11.
I tried the attachEvent function, but i didn't find the right code.
I'm very thankful for every help.
It would be a pleasure if anybody could tell me the little code part.
Thank you!!
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
.nav-bar {
position: fixed;
z-index: 1;
background-color: red;
top: 0;
left: -100%;
height: 100%;
width: auto;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
padding: 2%;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: white;
position: fixed;
top: 1rem;
left: 1rem;
width: 3.5rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
overflow: hidden;
background-clip: padding-box;
border: 3px solid black;
cursor: pointer;
}
.line {
width: 100%;
height: 4px;
border-radius:5px;
background-color: #000;
transition: 0.2s ease-out;
}
.toggle .line1 {
background-color: #e30513;
transform: scale(0.9) rotateZ(-45deg) translate(-8px, 8px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #e30513;
transform: scale(0.9) rotateZ(45deg) translate(-7px, -8px);
}
.toggle .toggle-menu {
background-color: white;
border: 0;
}
.nav-list {
list-style: none;
padding: 0;
line-height: 0.5;
}
.nav-list-item {
text-align: left;
padding: 1rem 0;
}
.nav-list-item a:hover{
color: white;
}
.nav-link {
color: #fff;
font-size: 1.3rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-list-item a:hover{
color: white;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="navigation">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Link 1</li>
<li class="nav-list-item">Link 2</li>
</ul>
</nav>
</div>
Try to replace your arrow function with a regular function as IE11 doesn't support arrow functions.
const toggleButton = document.querySelector('.toggle-menu');
const navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', function () {
navBar.classList.toggle('toggle');
});
I agree with the suggestion provided by Acidic9 regarding the arrow functions.
Arrow functions not supported in the IE browser and your JS code uses the arrow functions.
While running the code in the IE browser it will show the syntax error.
To fix the issue you need to remove the arrow function from your JS code.
Below is your problematic code:
toggleButton.addEventListener('click', () => {
navBar.classList.toggle('toggle');
});
It needs to replace with the code below will fix the issue.
toggleButton.addEventListener('click', function () {
navBar.classList.toggle('toggle');
});
Here is the full modified code:
var toggleButton = document.querySelector('.toggle-menu');
var navBar = document.querySelector('.nav-bar');
toggleButton.addEventListener('click', function () {
navBar.classList.toggle('toggle');
});
.nav-bar {
position: fixed;
z-index: 1;
background-color: red;
top: 0;
left: -100%;
height: 100%;
width: auto;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s ease-out;
padding: 2%;
}
.toggle {
left: 0;
box-shadow: 1px 0 15px 2px rgba(0, 0, 0, 0.4);
}
.toggle-menu {
background-color: white;
position: fixed;
top: 1rem;
left: 1rem;
width: 3.5rem;
height: 3rem;
display: flex;
flex-direction: column;
justify-content: space-around;
padding: 0.2rem 0.5rem;
border-radius: 0.5rem;
overflow: hidden;
background-clip: padding-box;
border: 3px solid black;
cursor: pointer;
}
.line {
width: 100%;
height: 4px;
border-radius:5px;
background-color: #000;
transition: 0.2s ease-out;
}
.toggle .line1 {
background-color: #e30513;
transform: scale(0.9) rotateZ(-45deg) translate(-8px, 8px);
}
.toggle .line2 {
display: none;
}
.toggle .line3 {
background-color: #e30513;
transform: scale(0.9) rotateZ(45deg) translate(-7px, -8px);
}
.toggle .toggle-menu {
background-color: white;
border: 0;
}
.nav-list {
list-style: none;
padding: 0;
line-height: 0.5;
}
.nav-list-item {
text-align: left;
padding: 1rem 0;
}
.nav-list-item a:hover{
color: white;
}
.nav-link {
color: #fff;
font-size: 1.3rem;
text-decoration: none;
position: relative;
padding-bottom: 0.4rem;
}
.nav-list-item a:hover{
color: white;
}
.nav-link::before {
position: absolute;
content: '';
left: 0;
bottom: 0;
width: 100%;
height: 1px;
background-color: #fff;
transform: scaleX(0);
transition: 0.4s ease-in-out;
transform-origin: left;
}
.nav-link:hover::before {
transform: scaleX(1);
}
<div class="navigation">
<nav class="nav-bar">
<div class="toggle-menu">
<div class="line line1"></div>
<div class="line line2"></div>
<div class="line line3"></div>
</div>
<ul class="nav-list">
<li class="nav-list-item">Link 1</li>
<li class="nav-list-item">Link 2</li>
</ul>
</nav>
</div>
Output in the IE 11 browser:
I am building a netflix-like slider in which a hovered slider-item pushes the other slider-items aside (depending on their location).
(see example code)
I can't find a solution to the following situation:
when I hover item 3, all other items are pushed aside to the left and right precisely as I want.
when item 2 is hovered, I want item 1 (or any item left of .item-left) to not move(stay in position). all others go as planned.
when item 4 is hovered, I want item 3/2/1 to keep the same distance from 4 as when not hovered. item 5 behaves correctly.
Hovered Items need to stay within the lightblue area (show-peek).
how can I make this work? Any help is welcome.
Thank you!
var slider = document.getElementById('sli');
var prev = document.getElementById('prev');
prev.addEventListener('click', prevC, false);
var next = document.getElementById('next');
next.addEventListener('click', nextC, false);
function prevC() {
alert('-1')
}
function nextC() {
alert('+1');
}
#import url(https://fonts.googleapis.com/css?family=Lato:300,400,700,900);
* {
box-sizing: border-box;
}
body {
font-family: 'Lato', sans-serif;
background-color: white/* rgba(20, 23, 26, .1) */
;
}
.page-head {
display: block;
top: 0;
left: 0;
width: 100%;
height: auto;
}
.page-head h1 {
font-size: 2em;
color: red;
text-align: center;
text-transform: uppercase;
padding: 20px;
}
/* general stuff */
.row {
display: block;
width: 400px;
margin: 0 auto;
/* overflow-x:hidden; */
}
.row-header {}
.row-header h2 {
font-size: 1.4em;
font-weight: 500;
padding: 8px 0;
margin-left: 45px;
}
.row-container {
position: relative;
}
.slider {
width: 100%;
padding: 0 41px 0 42px;
margin-top: 45px;
}
.slider .handle {
position: absolute;
top: 0;
bottom: 0;
z-index: 20;
width: 44px;
height: 69px;
text-align: center;
justify-content: center;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
color: #fff;
background: rgba(20, 20, 20, .3);
z-index: .9;
cursor: pointer;
line-height: 69px;
}
.handle-prev {
left: 0;
}
.handle-next {
right: 0;
}
.show-peek {
display: inline-block;
width: 316px;
height: 69px;
background: lightblue;
overflow-x: visible;
vertical-align: middle;
border: 1px dotted grey;
}
.slider-content {
display: block;
margin-top: 34px;
list-style: none;
white-space: nowrap;
transform: translateY(-50%) translateX(-100px);
text-align: center;
}
.slider-content:hover .slider-item {
opacity: 1;
transform: translateX(-49px);
transition-delay: .85s;
}
.slider-content:hover .slider-item:hover {
opacity: 1;
}
.slider-item {
position: relative;
vertical-align: middle;
display: inline-block;
list-style: none;
width: 100px;
height: 69px;
/* background-color: black; */
transition-duration: .3s;
overflow: hidden;
cursor: pointer;
border: 1px solid rgba(205, 20, 20, .3);
}
.slider-content li .bg-img {
position: absolute;
width: 100%;
height: 100%;
background-size: cover;
background-position: center top;
}
.slider-content li:hover {
transition-delay: 0.1s;
width: 200px;
height: 130px;
}
.slider-content .left-item:hover {
transform: translateX(0);
z-index: 999;
}
.slider-content .left-item:hover~.slider-item {
transform: translate3d(0px, 0, 0);
}
.slider-content .right-item:hover {
margin-left: -50px;
z-index: 999;
}
.slider-content li:hover a .content {
transform: translateY(0) translateX(-50%);
transition-delay: 0.75s;
opacity: 1;
}
.slider-content li a {
color: white;
text-decoration: none;
cursor: pointer;
width: 100%;
height: 100%;
display: block;
position: relative;
z-index: 2;
}
.slider-content li a .content {
background: linear-gradient(transparent, rgba(0, 0, 0, .75));
width: 100%;
height: 100px;
position: absolute;
bottom: 0;
left: 50%;
transform: translateY(100%) translateX(-50%);
transition-duration: .75s;
transition-delay: .4s;
opacity: 0;
padding: 40px 10px 10px 10px;
width: 400px;
}
.slider-content li a .content h2 {
font-weight: 300;
color: white;
font-size: 24px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css" rel="stylesheet"/>
<div class="row">
<div class="row-header">
<h2></h2>
</div>
<div class="row-container">
<div class="slider">
<span id="prev" class="handle handle-prev"><</span>
<div class="show-peek">
<ul class="slider-content">
<li class="slider-item">1</li>
<li class="slider-item left-item">2</li>
<li class="slider-item">3
</li>
<li class="slider-item right-item">4</li>
<li class="slider-item">5</li>
</ul>
</div>
<!-- ends show-peek -->
<span id="next" class="handle handle-next">></span>
</div>
<!-- ends slider -->
</div>
<!-- ends row-container -->
</div>
<!-- ends row -->
I did say that there was not really a CSS only solution but it seems you can be a bit creative..
You can take advantage of the -webkit-transform: scale CSS attribute.
Take your ul's and li's like so :
<ul class="slider-content">
<li id="1" class="slider-item">1</li>
<li id="2" class="slider-item">2</li>
<li id="3" class="slider-item">3</li>
<li id="4" class="slider-item">4</li>
</ul>
We can add some CSS to itterate over their order and modify their hover
ul{
list-style:none;
}
ul:hover li {
-webkit-transform: translateX(-25%);
transform: translateX(-25%);
}
ul:hover li:hover {
-webkit-transform: scale(1.5);
transform: scale(1.5);
transition-duration: 0.1818181818s;
}
ul:hover li:hover ~ li {
-webkit-transform: translateX(25%);
transform: translateX(25%);
}
.slider-item {
position: relative;
vertical-align: middle;
display: inline-block;
list-style: none;
width: 100px;
height: 69px;
/* background-color: black; */
transition-duration: .3s;
overflow: hidden;
cursor: pointer;
border: 1px solid rgba(205, 20, 20, .3);
}
.slider-content {
display: block;
margin-top: 34px;
list-style: none;
white-space: nowrap;
transform: translateY(-50%) translateX(-100px);
text-align: center;
}
<ul class="slider-content">
<li id="1" class="slider-item">1</li>
<li id="2" class="slider-item">2</li>
<li id="3" class="slider-item">3</li>
<li id="4" class="slider-item">4</li>
</ul>
This works by using the animations in CSS and some clever use of the translate css also.