React Multi-level push menu SCSS Back button not working - css

I am working on a Multi-level push navigation menu that will work for mobile users on my website. It is dynamically creating links based off projects on my GitHub account. The push menu I am using is from a codepen https://codepen.io/vixxofsweden/pen/xxGGYOE and I am trying to get it to work in react rather than just plain HTML, CSS. So far everything but the Back Button works.
But ironically when I when I go to the bottom of the page and press any of the empty space under "Shell" it acts like a back button and takes me to the previous menu. This push menu is not using any javascript, but I am open to using it if its able to fix this problem. I have tried trouble shooting this a multitude of times but some of this SCSS is alien to me.
My website is running on next.js using react. I will attach my render and my sass below. Let me know if you have any questions or need more info
This is the render() in the index.jsx
render() {
return (
<div className={`${this.renderCSS()}`}>
<div className="nav">
<nav>
<a className="mobile-menu-trigger">Open mobile menu</a>
{/* <button className={'mobile-menu-trigger'} >Mobile Menu</button> */}
<ul className="menu menu-bar">
<li>
<a className="menu-link menu-bar-link" aria-haspopup="true">Projects</a>
<ul className="mega-menu mega-menu--multiLevel">
<li className="mobile-menu-back-item">
<a className="menu-link mobile-menu-back-link">Back</a>
</li>
{Object.keys(this.props.languages).map(language => {
const allProjects = this.props.languages[language];
return (
<li key={language}>
<a className="menu-link mega-menu-link" aria-haspopup="true">{language}</a>
<ul className="menu menu-list">
{allProjects.map((item, index) => {
const project = this.props.projects[item];
const openGithubRepo = () => {
window.open(project.svn_url, "_blank");
}
const openGithubPages = () => {
window.open(`https://ngwessels.github.io/${project.name}/`, "_blank");
}
if (project.has_pages) {
return (
<li key={project.id}>
<a className="menu-link menu-list-link"
aria-haspopup="true">{project.name}</a>
<ul className="menu menu-list">
<li>
<a className="menu-link menu-list-link" onClick={openGithubRepo}>Open Github</a>
</li>
<li>
<a className="menu-link menu-list-link" onClick={openGithubPages}>Visit Live Example</a>
</li>
</ul>
</li>
);
} else {
return (
<li key={project.id}>
<a className="menu-link menu-list-link" onClick={openGithubRepo}>{project.name}</a>
</li>
)
}
})}
</ul>
</li>
)
})}
</ul>
</li>
<li>
<a className="menu-link menu-bar-link">Static link</a>
</li>
{/* <li className="mobile-menu-header">
<a className="">
<span>Home</span>
</a>
</li> */}
</ul>
</nav>
</div>
</div>
)
}
And here is the styles.scss
$color-accent: black;
$color-light: #ffffff;
$color-dark: black;
$menu-link-padding: 20px 25px;
$breakpoint: 950px;
$mega-menu-multiLevel-colWidth: 100/3 + 0%;
$mobile-menu-back-height: "calc(1.4em + 40px)";
$mobile-menu-back-offset: "calc(0px - (1.4em + 40px))";
$menu-mobile-width: 350px;
// ------------------ SHARED STYLES
nav {
ul, li {
list-style: none;
padding: 0;
margin: 0;
}
a {
display: block;
text-decoration: none;
&:hover, &:visited {
text-decoration: none;
}
}
}
.nav {
a {
font-family: 'Arial Black';
}
}
.menu-bar {
background: $color-light;
display: flex;
}
.menu-link {
padding: $menu-link-padding;
background: $color-light;
color: $color-accent;
transition: background .2s, color .2s;
position: relative;
z-index: 1;
&[aria-haspopup="true"] {
padding-right: 40px;
&:after {
content: "";
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1397521/arrowRight.svg#accent');
background-size: 14px;
width: 14px;
height: 14px;
font-size:12px;
position: absolute;
right: 10px;
top:50%;
transform: translateY(-50%);
}
}
}
.mega-menu-header {
font-size: 1.2em;
text-transform: uppercase;
font-weight: bold;
color: darken($color-accent, 5%);
}
.mega-menu {
background: $color-light;
z-index: 10;
}
.mega-menu--multiLevel {
flex-direction: column;
}
// ------------------ MEDIA QUERIES
#media all and (max-width: $breakpoint) {
.nav {
padding: 20px;
}
.mobile-menu-trigger, .mobile-menu-header, .mobile-menu-back-item {
display: block;
}
.mobile-menu-trigger {
background: $color-accent;
color: $color-light;
border: 0;
padding: 10px;
font-size: 1.2em;
border-radius: 4px;
}
.mobile-menu-header {
order: -1;
background: grey;
a {
padding: $menu-link-padding;
color: $color-light;
visibility: visible;
}
}
.menu-bar {
flex-direction: column;
position: fixed;
top: 0;
left: -100%;
height: 100vh;
width: $menu-mobile-width;
max-width: $menu-mobile-width;
max-width: 90%;
overflow-x: hidden;
transition: left .3s;
box-shadow: 1px 0px 2px 0px rgba(0,0,0,0.25);
background-color: white;
z-index: 1000;
> li {
> [aria-haspopup="true"] {
~ ul {
display: flex;
flex-direction: column;
background: $color-light;
position: absolute;
left: 100%;
top: 0;
max-height: 100vh;
width: 100%;
transition: left .3s;
// Second level
> li {
> [aria-haspopup="true"] {
font-size: 1.2em;
~ ul {
a {
padding-left: 40px;
}
// Third level
> li {
> [aria-haspopup="true"] {
~ ul {
a {
padding-left: 80px;
}
}
}
}
}
}
}
[aria-haspopup="true"] {
color: $color-dark;
&:after {
content: "+";
background: none;
font-size: 1em;
font-weight: normal;
height: 20px;
line-height: 1;
}
~ ul {
max-height: 0px;
transform-origin: top;
transform: scaleY(0);
transition: max-height .1s;
}
}
}
}
}
}
.mega-menu-content {
padding: $menu-link-padding;
}
.mobile-menu-back-item {
order: -1;
z-index: 1000000000;
a {
background: tint(grey, 70%);
color: $color-dark;
max-height: $mobile-menu-back-height;
margin-top: $mobile-menu-back-offset;
pointer-events: none;
&:before {
z-index: 1000000000;
content: "";
width: 14px;
height: 12px;
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1397521/arrowLeft.svg#default');
background-size: 14px;
margin-right: 10px;
display: inline-block;
}
}
}
// ------------------------ ALL DEVICES
.mobile-menu-trigger {
// FUNCTIONALITY: Open mobile menu
&:focus {
~ ul {
left: 0;
}
}
}
.menu-bar {
// FUNCTIONALITY: Keep menu open
&:hover, &:focus-within {
left: 0;
}
> li {
> [aria-haspopup="true"] {
// FUNCTIONALITY: Open mega menu
&:focus {
~ ul {
left: 0;
}
}
~ ul {
// STYLING: Back button offset
margin-top: $mobile-menu-back-height;
// FUNCTIONALITY: Keep mega menu open
&:hover, &:focus-within {
left: 0;
}
// FUNCTIONALITY: Open dropdowns
[aria-haspopup="true"] {
&:focus {
~ ul {
max-height: 500px;
animation: dropdown .3s forwards;
}
}
}
// FUNCTIONALITY: Keep dropdowns open
li {
&:focus-within {
> [aria-haspopup="true"] {
~ ul {
max-height: 500px;
transform: scaleY(1);
}
}
}
}
}
}
// FUNCTIONALITY: Prevent clicks on link behind back button
// &:focus-within ~ .mobile-menu-header a {
// visibility: visible;
// }
}
}
// ------------------------ TOUCH DEVICES
#media (hover: none) {
// FUNCTIONALITY: Open mobile menu
.mobile-menu-trigger {
&:hover {
~ ul {
left: 0;
}
}
}
// FUNCTIONALITY: Open mega menu
.menu-bar {
> li {
> [aria-haspopup="true"] {
&:hover {
~ ul {
left: 0;
}
}
~ ul {
&:hover {
left: 0;
}
// FUNCTIONALITY: Open dropdowns
[aria-haspopup="true"] {
&:hover {
~ ul {
max-height: 500px;
animation: dropdown .3s forwards;
}
}
~ ul {
&:hover {
max-height: 500px;
transform: scaleY(1);
}
}
}
}
}
// &:hover ~ .mobile-menu-header {
// a {
// visibility: hidden;
// }
// }
}
}
}
}
// ------------------ ANIMATIONS
#keyframes dropdown {
0% {
opacity: 0;
transform: scaleY(0);
}
50% {
opacity: 1;
}
100% {
transform: scaleY(1);
}
}
#keyframes flyout {
0% {
opacity: 0;
transform: scaleX(0);
}
100% {
opacity: 1;
transform: scaleX(1);
}
}

So I found a solution that involved using javascript to add styles to an element. If anyone finds a solution that only involves adding css let me know. Here is the code:
render() {
return (
<div className={`${this.renderCSS()}`}>
<div className="nav">
<nav>
<a className="mobile-menu-trigger">Open mobile menu</a>
<ul className="menu menu-bar" id={'menu-bar'}>
<li>
<a className="menu-link menu-bar-link" aria-haspopup="true" onClick={() => {
const el = document.getElementById('popup');
el.style.left = '0';
}}>Projects</a>
<ul className="mega-menu mega-menu--multiLevel" id={'popup'}>
<li className="mobile-menu-back-item">
<a className="menu-link mobile-menu-back-link" onClick={() => {
const el = document.getElementById('popup');
el.style.left = '100%';
}}>Back</a>
</li>
{Object.keys(this.props.languages).map(language => {
const allProjects = this.props.languages[language];
return (
<li key={language}>
<a className="menu-link mega-menu-link" aria-haspopup="true">{language}</a>
<ul className="menu menu-list">
{allProjects.map((item, index) => {
const project = this.props.projects[item];
const openGithubRepo = () => {
window.open(project.svn_url, "_blank");
}
const openGithubPages = () => {
window.open(`https://ngwessels.github.io/${project.name}/`, "_blank");
}
if (project.has_pages) {
return (
<li key={project.id}>
<a className="menu-link menu-list-link"
aria-haspopup="true">{project.name}</a>
<ul className="menu menu-list">
<li>
<a className="menu-link menu-list-link" onClick={openGithubRepo}>Open Github</a>
</li>
<li>
<a className="menu-link menu-list-link" onClick={openGithubPages}>Visit Live Example</a>
</li>
</ul>
</li>
);
} else {
return (
<li key={project.id}>
<a className="menu-link menu-list-link" onClick={openGithubRepo}>{project.name}</a>
</li>
)
}
})}
</ul>
</li>
)
})}
</ul>
</li>
<li>
<a className="menu-link menu-bar-link">Static link</a>
</li>
{/* <li className="mobile-menu-header">
<a className="">
<span>Home</span>
</a>
</li> */}
</ul>
</nav>
</div>
</div>
)
}

Related

How to change hamburger back to original state after clicking on mobile link from the expanded mobile menu?

I have figured out how to close the expanded mobile menu after a mobile link is clicked, but can't figure out how to return the hamburger icon back to the bars. I'm using the npm package hamburger-react.
Here's the component:
import React, { useState } from "react";
import "./Navbar.css";
import { Fade as Hamburger } from "hamburger-react";
const Navbar = () => {
window.addEventListener("scroll", function () {
const header = document.querySelector(".header");
header.classList.toggle("active", window.scrollY > 0);
});
window.addEventListener("scroll", function () {
const hamburger = document.querySelector(".hamburger");
hamburger.classList.toggle("active", window.scrollY > 0);
});
const [click, setClick] = useState(false);
const handleClick = () => setClick(!click);
const closeMenu = () => setClick(false);
return (
<div className="parent">
<div className="header d__flex justify__content__flex__end pxy__30">
<ul className={click ? "nav-menu active" : "nav-menu"}>
<li className="nav__items mx__15">
<a href="/" onClick={closeMenu}>
Home
</a>
</li>
<li className="nav__items mx__15">
<a href="#about" onClick={closeMenu}>
About
</a>
</li>
<li className="nav__items mx__15">
<a href="#projects" onClick={closeMenu}>
Projects
</a>
</li>
<li className="nav__items mx__15">
<a href="#contact" onClick={closeMenu}>
Contact
</a>
</li>
</ul>
<Hamburger
className="hamburger-react"
color="white"
direction="right"
rounded
onToggle={handleClick}
/>
</div>
</div>
);
};
export default Navbar;
Here's the css:
.parent {
height: 124px;
}
img {
padding-top: 5px;
}
.nav__items {
font-size: 18px;
}
.nav-menu {
display: flex;
text-transform: uppercase;
letter-spacing: 1px;
}
.nav-link {
color: #fff;
}
ul a {
display: inline-block;
position: relative;
padding: 1.5em 0;
}
ul a:hover {
color: #f9004d;
}
ul a::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0.2em;
background-color: #f9004d;
opacity: 0;
transition: opacity 300ms, transform 300ms;
}
ul a:hover::after,
ul a:focus::after {
opacity: 1;
transform: translate3d(0, 0.2em, 0);
}
/* Scale from center */
ul a::after {
opacity: 1;
transform: scale(0);
transform-origin: center;
}
ul a:hover::after,
ul a:focus::after {
transform: scale(1);
}
.hamburger-react {
display: none;
position: fixed;
/* top: 3.2rem; */
top: 1rem;
right: 2rem;
transition: 0.4s all ease;
cursor: pointer;
}
.hamburger-react.active {
position: fixed;
/* z-index: 1000; */
top: 1.5rem;
right: 2rem;
}
.header {
transition: 0.4s all ease;
}
.header.active {
position: fixed;
z-index: 1;
width: 100%;
padding: 0px 30px;
background-color: #010101;
}
#media only screen and (max-width: 960px) {
.hamburger-react {
display: block;
z-index: 2;
}
.nav-menu {
position: fixed;
right: -100%;
flex-direction: column;
justify-content: center;
background-color: #010101;
width: 100%;
height: 100%;
text-align: center;
transition: 0.4s;
top: 0%;
}
.nav-menu.active {
right: 0;
z-index: 1;
}
.nav__items {
font-size: 1.5rem;
}
}
I feel like I need to add some more functionality to the closeMenu function that would return the hamburger back to bars, but haven't been successful.
Assuming that the goal is to change the hamburger icon back to the inactive look when closeMenu fires, try set toggled={click} as a prop for Hamburger.
It seems that the click state is intended to control the icon, and its handler events are all set, so Hamburger should just need to set it for toggled to get controlled.
<Hamburger
className="hamburger-react"
color="white"
direction="right"
rounded
// 👇 Pass the state to control the component
toggled={click}
onToggle={handleClick}
/>

CSS Transition and Fixed position not working in Safari

//Menu Functionality
var menuButton = document.getElementById("menu-button");
menuButton.addEventListener("click",openNav);
var mainNav = document.getElementById("main-nav");
var btns = mainNav.getElementsByClassName("nav-link");
for (var i=0; i < btns.length; i++)
{
btns[i].addEventListener("click", function() {
openNav();
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
}
);
}
function openNav() {
var mainNav = document.getElementById("main-nav");
var menuButton = document.getElementById("menu-button");
mainNav.classList.toggle("open-nav");
if(menuButton.style.transform == ""){
menuButton.style.webkitTransform = "rotateY(180deg)";
}else {
menuButton.style.webkitTransform = "";
}
}
body {
font-family: "BrownPro",sans-serif;
font-size: 1.5em;
}
h2 {
font-weight: bold;
}
a {
color: #5a65ba;
}
.jumbotron-fluid
{
background-color: #292055;
}
#jumbotron-video {
width: 100%;
}
video {
max-width: 100%;
}
#main-nav {
position: fixed;
height: 100%;
font-size: 2rem;
font-weight: bold;
text-align: center;
z-index: 1;
top: 0;
width: 60%;
overflow-x: hidden;
transition:left 0.5s;
padding-top: 60px;
background-image: linear-gradient(100deg, #292055 calc(80% - 10%), transparent 0px);
}
nav a {
margin: 20px;
}
nav a:hover {
color: white;
}
.close-nav {
left: -60%;
}
.open-nav {
left: 0%;
}
#menu-button {
position: fixed;
margin-left: 2%;
max-width: 8%;
font-size: 2em;
top: 6%;
z-index: 2;
color: #ec008c;
cursor: pointer;
opacity: 75%;
transition: transform .5s;
}
.active {
color: white;
/*background-color: #5a65ba;*/
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
<div class="jumbotron-fluid">
<img id="menu-button" src="http://www.posible.strangelandcreative.com/img/menu%20button.png" alt="menu-button"/>
<video id="jumbotron-video" muted loop>
<source src="https://player.vimeo.com/external/437237782.hd.mp4?s=19c3a456176f98a3e348659b2b90b230391dd3e2&profile_id=175" type="video/mp4">
</video>
<nav id="main-nav" class="close-nav justify-content-center navigation">
<a class="nav-link active text-align-center" href="#mision_id">MISIÓN</a>
<a class="nav-link" href="#eventos_id">EVENTOS</a>
<a class="nav-link" href="#aprende_id">APRENDE</a>
<a class="nav-link " href="#recursos_id">RECURSOS</a>
<a class="nav-link" href="#galeria_id">GALERÍA</a>
<a class="nav-link" href="#contact_id">CONTÁCTANOS</a>
</nav>
</div>
So as usual this is a Safari problem only. I have tried several things to make this menu animation work to no avail. The menu button doesn't seem to respect the z index and the animation glitches out too. I have tried several suggestions on here and nothing has worked. Using the -webkit- prefix on the classes hasn't done anything. Getting rid of transitions didn't do anything.
I tried this on the menu container
-webkit-transform: translate3d(0px, 0px, 0px);
I tried on the button
transform: translateZ(1000px);
transform-style: preserve-3d;
Nothing solves this bug. On chrome and firefox works perfectly.

Custom WordPress nav menu the last li item – two social icons

I need to create WordPress custom nav menu containing two social icons in the last li item.
document.addEventListener('DOMContentLoaded', function() {
// Toggle
const btn = document.querySelector('#btnToggle');
btn.addEventListener('click', function(e) {
e.preventDefault();
document.body.classList.toggle('nav-show');
this.classList.toggle('btn-toggle--toggled');
});
// Highlight current page active menu item.
const selector = '.nav__link';
const elems = Array.from(document.querySelectorAll(selector));
const navigation = document.querySelector('nav');
function makeActive(evt) {
const target = evt.target;
if (!target || !target.matches(selector)) {
return;
}
elems.forEach(elem => elem.classList.remove('active'));
evt.target.classList.add('active');
};
navigation.addEventListener('mousedown', makeActive);
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
overflow-x: hidden;
}
img {
max-width: 100%;
display: block;
}
.social__link {
display: block;
}
svg {
width: 100%;
display: block;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
.container {
margin: 0 auto;
width: 100%;
max-width: 1400px;
}
.header {
position: sticky;
top: 0;
background-color: #fff;
z-index: 1;
}
.logo__container {
padding: .3125rem .3125rem .625rem;
}
.logo {
display: flex;
align-items: center;
}
.logo__heart {
flex-basis: 27%;
}
.hgroup {
padding-left: .625rem;
}
.headline__light {
display: none;
}
.headline {
font-size: 1.25rem;
text-transform: uppercase;
margin: 0;
}
.navigation__container {
align-items: center;
}
.header__item {
display: flex;
}
.btn-toggle button {
background: none;
border: 0;
}
.btn-toggle {
width: 40px;
height: 40px;
cursor: pointer;
border: 1px solid #DDD;
border-radius: 4px;
padding: 9px;
position: absolute;
top: 24px;
right: 20px;
background: none;
}
.btn-toggle .line {
background: #888;
border-radius: 10px;
display: block;
position: absolute;
height: 2px;
transform: translate(-50%, -50%) rotate(0deg);
transition: transform 0.25s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
opacity: 1;
top: 50%;
left: 50%;
width: 80%;
}
.btn-toggle .line:nth-child(1) {
margin-top: -6px;
}
.btn-toggle .line:nth-child(3) {
margin-top: 6px;
}
.btn-toggle--toggled .line:nth-child(2) {
opacity: 0;
}
.btn-toggle--toggled .line:nth-child(1) {
margin-top: 0;
transform: translate(-50%, -50%) rotate(45deg);
}
.btn-toggle--toggled .line:nth-child(3) {
margin-top: 0;
transform: translate(-50%, -50%) rotate(-45deg);
}
.nav {
background: #F2EFE8;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
max-height: 0;
overflow: hidden;
transition: 0.5s max-height;
}
.nav-show .nav {
max-height: 700px;
}
.nav__list {
display: flex;
flex-direction: column;
background: #F2EFE8;
border-top: 1px solid #DDD;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}
.nav__item {
flex-basis: 100%;
text-transform: uppercase;
font-size: .875rem;
text-align: center;
border-bottom: 1px solid #888;
letter-spacing: .0625rem;
}
.nav__link {
display: block;
text-decoration: none;
text-transform: uppercase;
color: #222;
padding: .625rem;
}
.nav__link:hover {
background: #c2def7;
}
.nav__link.active {
background: #abd4f8;
}
.icon__container {
display: flex;
justify-content: space-evenly;
align-items: center;
}
.nav__item.social__icon {
padding: .625rem;
}
.icon {
width: 10%;
}
#media only screen and (min-device-width: 320px) and (max-device-width: 568px) and (orientation: landscape) {
.nav__list {
flex-direction: row;
flex-wrap: wrap;
}
.nav__item {
width: 50%;
flex-basis: 50%;
}
.nav__item:nth-of-type(1) {
order: 1;
}
.nav__item:nth-of-type(2) {
order: 3;
}
.nav__item:nth-of-type(3) {
order: 5;
}
.nav__item:nth-of-type(4) {
order: 7;
}
.nav__item:nth-of-type(5) {
order: 9;
}
.nav__item:nth-of-type(6) {
order: 2;
}
.nav__item:nth-of-type(7) {
order: 4;
}
.nav__item:nth-of-type(8) {
order: 6;
}
.nav__item:nth-of-type(9) {
order: 8;
}
.nav__item:nth-of-type(10) {
order: 10;
padding: .3125rem 0;
border-bottom: 1px solid #888;
}
.icon {
width: 9%;
}
}
#media only screen and (min-width: 768px) {
.logo__heart {
flex-basis: 25%;
}
.hgroup {
flex-basis: 71%;
}
.headline__light {
display: block;
font-size: .875rem;
text-transform: none;
}
.nav__list {
flex-grow: 1;
flex-wrap: wrap;
flex-direction: row;
}
.nav__item {
width: 33.33%;
flex-basis: 33.33%;
}
.nav__item:nth-of-type(1) {
order: 1;
}
.nav__item:nth-of-type(2) {
order: 4;
}
.nav__item:nth-of-type(3) {
order: 7;
}
.nav__item:nth-of-type(4) {
order: 2;
}
.nav__item:nth-of-type(5) {
order: 5;
}
.nav__item:nth-of-type(6) {
order: 8;
}
.nav__item:nth-of-type(7) {
order: 3;
}
.nav__item:nth-of-type(8) {
order: 6;
}
.nav__item:nth-of-type(9) {
order: 9;
}
.nav__item:nth-of-type(10) {
order: 10;
padding: .625rem;
flex-basis: 100%;
}
.icon {
width: 4%;
}
}
#media only screen and (min-width: 1024px) {
.logo {
width: 100%;
}
.logo__heart {
flex-basis: 30%;
}
.hgroup {
flex-basis: 100%;
padding: 0;
}
.unboxing__trick {
background-color: #F2EFE8;
width: 100vw;
position: relative;
margin: 0 calc(-50vw + 50%);
padding: 0 calc(50vw - 50%);
}
.btn-toggle {
display: none;
}
.nav {
max-height: 100%;
transition: none;
transition-duration: 0s;
display: flex;
flex-direction: row;
}
.nav__list {
flex-direction: row;
flex-wrap: nowrap;
border-top: none;
padding: .625rem 0;
}
.nav__item {
flex-basis: auto;
width: auto;
flex-grow: 1;
flex: 1 1 auto;
position: relative;
border-bottom: none;
}
.nav__item:after {
content: '';
position: absolute;
width: 1px;
left: 0;
top: 0;
bottom: 0;
background: linear-gradient(hsla(0, 0%, 0%, 0) 0%, hsla(0, 0%, 0%, .20) 50%, hsla(0, 0%, 0%, 0) 100%);
}
.nav__item:last-of-type {
border-right: 0;
}
.nav__item:nth-of-type(1) {
order: 1;
}
.nav__item:first-child::after {
display: none;
}
.nav__item:nth-of-type(2) {
order: 2;
}
.nav__item:nth-of-type(3) {
order: 3;
}
.nav__item:nth-of-type(4) {
order: 4;
}
.nav__item:nth-of-type(5) {
order: 5;
}
.nav__item:nth-of-type(6) {
order: 6;
}
.nav__item:nth-of-type(7) {
order: 7;
}
.nav__item:nth-of-type(8) {
order: 8;
}
.nav__item:nth-of-type(9) {
order: 9;
}
.nav__item:nth-of-type(10) {
order: 10;
flex: 1 1 8%;
padding: .3125rem 0;
border-bottom: none;
}
.nav__link:hover {
background: none;
color: #b8795a;
}
.nav__link.active {
background: none;
color: #b8795a;
}
.icon {
width: 25px;
}
}
#supports (position: sticky) {
.header {
position: sticky;
top: 0;
}
}
<!doctype html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="style.css">
<script src="app.js"></script>
</head>
<body>
<header class="header">
<section class="container">
<div class="header__container">
<div class="logo__container header__item">
<div class="logo">
<div class="logo__heart">
<img class="img__logo" src="http://placehold.it/169x160" alt="" title="">
</div>
<div class="hgroup">
<h1 class="headline__bold headline">Czysta świadomość</h1>
<h2 class="headline__light headline">
... stan bycia poza umysłem, wolny od goniących myśli, wszelkich uwarukowań, pobudek ego.<br> Czysta Świadomość to prawdziwe JA... to Światło i Miłość
</h2>
</div>
</div>
</div>
<nav class="navigation__container">
<button class="btn-toggle" id="btnToggle" aria-label="Open / Close Menu">
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
</button>
<div class="unboxing__trick">
<div class="nav">
<ul class="nav__list">
<li class="nav__item">
<a class="nav__link active" href="#">Strona Główna</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Ja jestem</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Kalendarz</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Warsztaty</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Wykłady</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Artykuły</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Audio</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Youtube</a>
</li>
<li class="nav__item">
<a class="nav__link" href="#">Kontakt</a>
</li>
<li class="nav__item social__icon">
<figure class="icon__container">
<div class="icon">
<a class="social__link social__link--fb" href="#">
<svg version="1.1" id="Social_Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-297.5 123.5 595 595" enable-background="new -297.5 123.5 595 595" reserveAspectRatio="xMidYMid meet" xml:space="preserve">
<rect x="-64.47" y="206.101" fill="#FFFFFF" width="276.871" height="512.399"/>
<path id="Facebook" fill="#4460A0" d="M20.309,718.5H-264.66c-18.143,0-32.84-14.707-32.84-32.84V156.342
c0-18.144,14.698-32.842,32.84-32.842h529.324c18.135,0,32.836,14.698,32.836,32.842V685.66c0,18.137-14.701,32.84-32.836,32.84
H113.042V488.082h77.34l11.581-89.799h-88.921v-57.328c0-26,7.218-43.713,44.5-43.713l47.548-0.02v-80.316
c-8.223-1.092-36.449-3.538-69.289-3.538c-68.561,0-115.496,41.851-115.496,118.698v66.222H-57.23v89.798H20.31V718.5H20.309z"/>
</svg>
</a>
</div>
<div class="icon">
<a class="social__link social__link--youtube" href="#">
<svg version="1.1" id="Social_Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 36.305 595 595" enable-background="new 0 36.305 595 595" reserveAspectRatio="xMidYMid meet" xml:space="preserve">
<polygon fill="#FFFFFF" points="214.04,443.136 214.04,214.49 432.938,328.812 "/>
<path id="Youtube" fill="#CE1312" d="M589.05,214.115c0,0-5.819-41.248-23.65-59.408c-22.629-23.849-47.991-23.959-59.611-25.343
c-83.265-6.06-208.158-6.06-208.158-6.06h-0.261c0,0-124.895,0-208.157,6.06c-11.641,1.384-36.984,1.495-59.63,25.343
C11.75,172.873,5.948,214.115,5.948,214.115S0,262.565,0,310.993v45.417c0,48.445,5.949,96.875,5.949,96.875
s5.802,41.247,23.633,59.407c22.647,23.851,52.379,23.102,65.617,25.591c47.6,4.602,202.301,6.021,202.301,6.021
s125.024-0.185,208.288-6.246c11.621-1.4,36.983-1.514,59.611-25.36c17.831-18.166,23.652-59.408,23.652-59.408
S595,404.859,595,356.41v-45.417C595,262.565,589.05,214.115,589.05,214.115z M236.066,411.443l-0.019-168.18l160.762,84.38
L236.066,411.443z"/>
</svg>
</a>
</div>
</figure>
</li>
</ul>
</div>
</div>
</nav>
</div>
</section>
</header>
</body>
</html>
I cannot comment on Marco’s answer because I have not enough reputation, so I create a new answer…
Marco’s code only needs a small adjustment, then it should work: The social icons markup needs to be added to $items, and in the end, $items needs to be returned by the filter function.
function add_last_nav_item( $items ) {
$items .= sprintf(
'<li class="nav__item social__icon">
<figure class="icon__container">
<div class="icon">
<img src="%2$s/images/icon__facebook.svg">
</div>
<div class="icon">
<img src="%2$s/images/icon__youtube.svg"> .
</div>
</figure>
</li>',
'https://www.facebook.com/Czysta-%C5%9Awiadomo%C5%9B%C4%87-%C5%9Awiat%C5%82o-i-Mi%C5%82o%C5%9B%C4%87pl-811435542275919/',
get_template_directory_uri(),
'https://www.youtube.com/channel/UCxxKwAW7JE6eCx3OjNcO6Yw/'
);
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_last_nav_item' );
Update for adding classes
To add a class to the li and a elements of the nav items, you can use the following snippet:
/**
* Add classes to li and a elements of the nav menus.
*
* #param string $items HTML of menu items.
*
* #return string
*/
function themeslug_add_menu_item_classes( $items ) {
// Disable libxml errors.
libxml_use_internal_errors( true );
// Create new DOMDocument object.
$dom = new DOMDocument();
// Load the HTML.
// Trick with <?xml endocing="utf-8" loadHTML() method of https://github.com/ivopetkov/html5-dom-document-php
$dom->loadHTML( '<?xml encoding="utf-8" ?>' . $items, 0 | LIBXML_NOENT );
$xpath = new DOMXPath( $dom );
// Get all nodes.
$nodes = $xpath->query( '//*' );
// Loop them.
foreach ( $nodes as $node ) {
// Check if we have an li element.
if ( 'li' === $node->tagName ) {
// Get existing classes from element and add our custom class.
$classes = $node->getAttribute( 'class' ) . ' my-custom-list-item-class';
// Set the custom class.
$node->setAttribute( 'class', $classes );
} // End if().
// Check if the node is an a element.
if ( 'a' === $node->tagName ) {
// Get existing classes from element and add our custom class.
$classes = $node->getAttribute( 'class' ) . ' my-custom-a-element-class';
// Set the custom class.
$node->setAttribute( 'class', $classes );
} // End if().
} // End foreach().
// Save the dom.
$items = themeslug_save_html( $dom );
// Return the items.
return $items;
}
add_filter( 'wp_nav_menu_items', 'themeslug_add_menu_item_classes' );
/**
* Enhanced variation of DOMDocument->saveHTML().
*
* Fix for cyrillic from https://stackoverflow.com/a/47454019/7774451.
* Replacement of doctype, html, and body from archon810\SmartDOMDocument.
*
* #param DOMDocument $dom DOMDocument object of the dom.
*
* #return string DOM or empty string.
*/
function themeslug_save_html( DOMDocument $dom ) {
$xpath = new DOMXPath( $dom );
$first_item = $xpath->query( '/' )->item( 0 );
return preg_replace(
array(
'/^\<\!DOCTYPE.*?<html><body>/si',
'!</body></html>$!si',
),
'',
$dom->saveHTML( $first_item )
);
}
It uses DOMDocument to parse the HTML of the nav items and DOMXPath to get all HTML nodes. After that, the nodes are looped and inside the loop it checks for the element type and adds a class if it is a li or a element.
could you paste this code on your functions.php
it should add the li at the end of your wp_nav_menu()
function add_last_nav_item($items) {
?>
<li class="nav__item social__icon">
<figure class="icon__container">
<div class="icon">
<img src="<?php echo get_template_directory_uri(); ?>/images/icon__facebook.svg">
</div>
<div class="icon">
<img src="<?php echo get_template_directory_uri(); ?>/images/icon__youtube.svg"> .
</div>
</figure>
</li>
<?php
}
add_filter('wp_nav_menu_items','add_last_nav_item');
You can extend the WordPress Walker class to build a custom menu.
Have a look at the codex documentation.
https://codex.wordpress.org/Class_Reference/Walker
You need to apply the required logic in that. Do not use jQuery or frontend scripts to do that. The menu is fully customiszable with the Walker.

How to set the width of absolute positioned droppdown menu to fit the longest list item?

I have a header with 2 dropdowns.
the dropdown menu position is absolute to it's wrapper container.
I want each dropdown menu width fit to the size of longest list entry. I am wondering if there is any solution without looping through li s and achieve it only using css?
<nav>
<div class="nav-dropdownContainer">
<div class="navdropdown nav-primary__dropdown">
<div class="navdropdown__text">
Themes
<i class="fa fa-chevron-down">+</i>
</div>
<ul class="navdropdown__list">
<li class="navdropdown__listItem">linktheme1</li>
<li class="navdropdown__listItem">linktheme2</li>
</ul>
</div>
<div class="navdropdown nav-primary__dropdown">
<div class="navdropdown__text">
tags
<i class="fa fa-chevron-down">+</i>
</div>
<ul class="navdropdown__list">
<li class="navdropdown__listItem">linktag1</li>
<li class="navdropdown__listItem">linktag2</li>
</ul>
</div>
</div>
</nav>
And CSS:
ul{
margin: 0;
padding: 0;
}
nav{
background-color: grey;
line-height: 35px;
}
.nav-dropdownContainer {
height: 70px;
width: 25%;
display: inline-block;
position: relative;
}
.navdropdown {
background-color: #455565;
display: inline-block;
border-right: 1px solid #fff;
height: 100%; }
.navdropdown:first-child {
border-left: 1px solid #fff; }
.navdropdown > ul {
margin: 0; }
.navdropdown:hover .navdropdown__text {
color: #fff; }
.navdropdown.open .navdropdown__text {
color: #fff; }
.navdropdown.open .navdropdown__list {
display: block; }
.navdropdown .fa-chevron-up,
.navdropdown .fa-chevron-down {
padding-left: 1rem;
font-size: 0.875rem; }
.navdropdown .navdropdown__text {
text-align: center;
cursor: pointer;
color: #ccc;
border-top: none;
padding: 1rem; }
.navdropdown__list {
position: absolute;
top: 100%;
z-index: 1000;
display: none;
float: left;
width: 100%;
left: 0;
background-color: #455565;
list-style-type: none; }
.navdropdown__list .navdropdown__listItem {
width: 100%;
float: left;
padding: 1rem;
background-color: #374350;
margin: 0; }
.navdropdown__list .navdropdown__listItem > a {
text-decoration: none;
color: #fff;
cursor: pointer; }
.navdropdown__list .navdropdown__listItem:hover {
background-color: #374856; }
JS:
(function() {
// Cache DOM
var $body = $('body'),
$window = $(window),
_dropdownClassName = '.navdropdown',
$dropdownContainer = $('.nav-dropdownContainer');
$body.on('click', _dropdownClassName, toggleDropdown);
function closeAllDropdowns(){
$(_dropdownClassName).removeClass('open');
$('.navdropdown__text i').removeClass('fa-chevron-up').addClass('fa-chevron-down');
}
/**
* toggle dropdown
*/
function toggleDropdown(){
const $this = $(this);
const $thisArrow = $this.find('.navdropdown__text i');
var leftPosition = $this.offset().left - $dropdownContainer.offset().left;
console.log('leftPosition', leftPosition);
if (window.Modernizr.mq('only screen and (max-width: 64em)')) {
$this.find('.navdropdown__list').css('left', 0);
}else{
if(leftPosition > 0){
$this.find('.navdropdown__list').css('left', leftPosition+'px');
}
}
if($thisArrow.hasClass('fa-chevron-down')){
closeAllDropdowns();
$this.addClass('open');
$thisArrow.removeClass('fa-chevron-down').addClass('fa-chevron-up');
}else{
closeAllDropdowns();
}
}
})();
Code Pen link: http://codepen.io/neginbasiri/pen/Xjgwkx
Add this to your navdropdown class : min-width: 40%;
It sets the minimum width of them to 40% of it's container width(If you have more items set this percentage proportional to the number of items).
If you want it be exactly like the biggest width involves some javascripts I don't recommend that way.

BootStrap Continuous Slide [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Here is a strip down version of my website. Using the mobile view, when the slides transitions there is a blank wipe before then next slide comes in
http://www.bootply.com/vUXtZz6HQ2
I am not quite understanding what I have to do to get the continuousswipe, that is the current slide will slide off as the next comes on the screen so it looks like it is one continuous strip,
as in the example of Bootstrap Carousel
HTML
<section class="marquee row">
<div class="carousel slide article-slide" data-ride="carousel" data-pause="hover" id="mainPromotion" style="-webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); touch-action: none;">
<div class="carousel-inner">
<div class="item" data-cell-id="" data-interval="7000">
<div class="marquee-media" data-src-md="http://placehold.it/300&text=A" data-src-xs="http://placehold.it/300&text=A" data-link="http://placehold.it/300&text=A" data-link-target="" data-link-title="A" id="marquee0"><img class="marquee-image img-responsive" src="http://placehold.it/300x300&text=A"></div>
</div>
<div class="item" data-cell-id="" data-interval="7000">
<div class="marquee-media" data-src-md="http://placehold.it/300&text=B" data-src-xs="http://placehold.it/300&text=B" data-link="http://placehold.it/300&text=B" data-link-target="" data-link-title="B" id="marquee1"><img class="marquee-image img-responsive" src="http://placehold.it/300&text=B"></div>
</div>
<div class="item active" data-cell-id="" data-interval="7000">
<div class="marquee-media" data-src-md="http://placehold.it/300&text=B" data-src-xs="http://placehold.it/300&text=C" data-link="http://placehold.it/300&text=C" data-link-target="" data-link-title="C" id="marquee2"><img class="marquee-image img-responsive" src="http://placehold.it/300&text=C"></div>
</div>
</div>
<ol class="carousel-indicators clearfix">
<li class="" data-slide-to="0" data-target="#mainPromotion">
<img alt="A" src="http://placehold.it/300&text=A">
<p class="cell-text">A</p>
<i class="fa fa-caret-right fa-2x"></i>
</li>
<li data-slide-to="1" data-target="#mainPromotion" class="">
<img alt="B" src="http://placehold.it/300&text=B">
<p class="cell-text">B</p>
<i class="fa fa-caret-right fa-2x"></i>
</li>
<li data-slide-to="2" data-target="#mainPromotion" class="active">
<img alt="C" src="http://placehold.it/300&text=C">
<p class="cell-text">C</p>
<i class="fa fa-caret-right fa-2x"></i>
</li>
</ol>
</div>
</section>
CSS
/* CSS used here will be applied after bootstrap.css */
section.marque {
margin-top: 10px;
}
section.marquee .cell-text {
color: #777777;
position: relative;
padding: 5px;
font-weight: bold;
font-family: ProximaNova, Arial, Helvetica, sans-serif;
display: inline-block;
float: left;
vertical-align: middle;
text-align: left;
text-indent: 0;
height: 60px;
width: 125px;
}
section.marquee .cell-text:hover {
background-color: #00543d;
color: #ffffff;
}
section.marquee .carousel-control {
background-image: none !important;
}
section.marquee .next.left,
section.marquee .prev.right {
-ms-opacity: 1;
opacity: 1;
z-index: 0;
}
section.marquee .active.left,
section.marquee .active.right {
-ms-opacity: 0;
opacity: 0;
z-index: 0;
}
section.marquee .article-slide .carousel-indicators {
top: 0;
left: 18px;
margin-left: 0;
margin-top: 8px;
width: 204px;
z-index: 0;
}
section.marquee .article-slide .carousel-indicators img {
/*float: left;
left: 0;*/
display: inline-block;
float: left;
width: 70px;
height: auto !important;
}
section.marquee .carousel-indicators li {
text-indent: 0 !important;
border: 1px solid #c0c0c0;
display: inline-block;
-ms-border-radius: 0;
border-radius: 0;
margin-bottom: 2px;
margin-left: -2px;
width: auto;
height: auto !important;
line-height: 16px;
font-size: 15px;
background-color: white;
z-index: 0;
position: relative;
}
section.marquee .carousel-indicators li i {
display: none;
}
section.marquee .carousel-indicators li:hover .cell-text {
background-color: #00543d;
color: #ffffff;
}
section.marquee .carousel-indicators li.active .cell-text {
color: #00543d;
}
section.marquee .carousel-indicators li.active:hover .cell-text {
color: #ffffff;
}
section.marquee .carousel-indicators li.active {
border: 3px solid #00543d;
color: #00543d;
margin-left: -1px;
margin-bottom: -1px;
}
section.marquee .carousel-indicators li.active i {
display: block;
position: absolute;
text-indent: 0 !important;
right: -12px;
top: 15px;
}
section.marquee .edit-marquee-cell {
position: absolute;
top: 5px;
left: 45%;
}
#media (min-width: 768px) and (max-width: 991px) {
section.marquee .item img,
section.marquee .carousel {
width: 768px;
height: 300px;
}
}
#media (min-width: 1200px) {
section.marquee .item img,
section.marquee .carousel {
width: 100% !important;
height: auto !important;
}
}
#media (min-width: 991px) {
/* fade effect */
section.marquee .carousel .item {
z-index: 0;
left: 0 !important;
-webkit-transition: opacity .4s;
-moz-transition: opacity .4s;
-o-transition: opacity .4s;
-ms-transition: opacity .4s;
transition: opacity .4s;
}
}
#media(max-width : 991px) {
section.marquee .carousel-indicators li.active i,
section.marquee .carousel-indicators img,
section.marquee .carousel-indicators .cell-text {
display: none !important;
}
section.marquee .carousel-indicators {
position: relative !important;
margin-left: auto !important;
margin-right: auto !important;
width: 80px !important;
text-align: center !important;
left: auto !important;
right: auto !important;
top: auto !important;
bottom: 0;
}
section.marquee .carousel-indicators li {
display: inline-block !important;
width: 15px !important;
height: 15px !important;
margin: 1px !important;
border: 1px solid #bcbcbc !important;
-ms-border-radius: 10px !important;
border-radius: 10px !important;
cursor: pointer;
}
section.marquee .carousel-indicators li.active {
width: 15px;
height: 15px !important;
background-color: #00543d !important;
}
backface-visibility: hidden;
perspective: 1000;
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
}
}
JavaScript
$(function () {
var validFlag = false;
$(window).on({
"load": function() {
if (!window.marqueeJson) return;
var imageTemplate = Handlebars.compile($("#template-marquee-images").html());
var fragTemplate = Handlebars.compile($("#template-marquee-frags").html());
var compiledInner = $("section.marquee .carousel-inner");
var compiledFrags = $("section.marquee .carousel-indicators");
compiledInner.html(imageTemplate(window.marqueeJson));
compiledFrags.html(fragTemplate(window.marqueeJson));
if (window.marqueeJson.Cells.length == 1) {
compiledFrags.remove();
$("section.marquee .carousel-control").remove();
}
if (compiledInner.length > 0) {
validFlag = true;
var mainPromo = document.getElementById("mainPromotion");
var mc = new window.Hammer(mainPromo);
mc.on("swipeleft", function () {
$(mainPromo).carousel("next");
});
mc.on("swiperight", function () {
$(mainPromo).carousel("prev");
});
updateMarquee();
var carouselStartPromo = function (promoPos) {
if (!isNaN(promoPos) && (0 < promoPos) && (promoPos < 3)) {
$('#mainPromotion').carousel(promoPos);
} else {
$('#mainPromotion').carousel();
}
};
var t;
var promoStart = -1;
carouselStartPromo(promoStart);
$('#mainPromotion').carousel('pause');
var start = $('#mainPromotion').find('.active').attr('data-interval');
t = setTimeout(carouselStartPromo, start - 7000);
/*
This event is to fix an IE bug where the swf file does not replay when the marquee control cycles
around. It looks ahead to the next item before the slide event happens (or to the first item, if there
isn't an item after the active one) and reloads the swf by re-embedding it. This only fires if the
useragent contains "MSIE" for Internet Explorer.
*/
$('#mainPromotion').on('slide.bs.carousel', function () {
if(navigator.userAgent.indexOf('MSIE') > -1){
var params = { menu: "false", wmode: "transparent" };
var self;
if ($('#mainPromotion').find('.active + .item').length > 0) {
self = $('#mainPromotion').find('.active + .item').find('.marquee-media');
}
else {
self = $('#mainPromotion').find('.item').first().find('.marquee-media');
}
var flashMedia = self.attr("data-src-flv") !== undefined ? self.attr("data-src-flv") : false;
if (flashMedia) {
var flashId = self.attr("id") + "-flash";
swfobject.embedSWF(flashMedia, flashId, "100%", "300", "9.0", false, false, params);
}
}
});
$('#mainPromotion').on('slid.bs.carousel', function () {
clearTimeout(t);
var duration = $('#mainPromotion').find('.active').attr('data-interval');
$('#mainPromotion').carousel('pause');
t = setTimeout(carouselStartPromo, duration - 7000);
});
/* Marquee Unit Tracking (cells tracking in handlebar helpers) */
if (window.marqueeJson.AnalyticId.length > 1) {
$("#mainPromotion").attr("data-tracking", window.marqueeJson.AnalyticId);
}
}
},
"resize": function() {
if (!validFlag) return;
waitForFinalEvent(function() {
updateMarquee();
}, 300, new Date().getTime());
}
});
function updateMarquee() {
});
Going through your code the problem is caused in the css with these styles
section.marquee .next.left,
section.marquee .prev.right {
-ms-opacity: 1;
opacity: 1;
z-index: 0;
}
section.marquee .active.left,
section.marquee .active.right {
-ms-opacity: 0;
opacity: 0;
z-index: 0;
}
Removing these will get it working. What is happening is that the opacity:0; is applying straight away and so you just get a blank square.
If what your looking to do is have a fade out fade in effect on the slides, I think transition : opacity 1s ease; might help.
see below image of class being applied.
line 40,
if (!isNaN(promoPos) && (0 < promoPos) && (promoPos < 3)) {
$('#mainPromotion').carousel(promoPos);
update 4 by 3.

Resources