There are cards, when you click on the checkmark, the card flies sideways, when you click on the cross, the card turns over to the correct answer. On this side there is a button, when you click on which the card flies to the side, as well as when you click on the checkmark. I have a problem with the last point. How to make it so that when you click on the button with the class next on the back of the card, the active card flies sideways? https://jsfiddle.net/kyen9gsw/
'use strict';
var quizcardContainer = document.querySelector('.quizcard');
var allCards = document.querySelectorAll('.flip-card');
var nope = document.getElementById('nope');
var love = document.getElementById('love');
var next = document.getElementById('next');
function initCards(card, index) {
var newCards = document.querySelectorAll('.flip-card:not(.removed)');
newCards.forEach(function (card, index) {
card.style.zIndex = allCards.length - index;
card.style.opacity = (10 - index) / 10;
});
quizcardContainer.classList.add('loaded');
}
initCards();
function createButtonListener(love) {
return function (event) {
var cards = document.querySelectorAll('.flip-card:not(.removed)');
var moveOutWidth = document.body.clientWidth * 0.3;
if (!cards.length) return false;
var card = cards[0];
card.classList.add('removed');
if (love) {
card.style.transform = 'translate(' + moveOutWidth + 'px, -900px) rotate(0deg)';
} else if (nope){
card.classList.toggle('do-flip');
document.querySelectorAll('next').onclick = function() {
card.style.transform = 'translate(' + moveOutWidth + 'px, 900px)';
};
}
initCards();
event.preventDefault();
};
}
var nopeListener = createButtonListener(false);
var loveListener = createButtonListener(true);
nope.addEventListener('click', nopeListener);
love.addEventListener('click', loveListener);
.quizcard {
width: 100vw;
height: 100vh;
overflow: hidden;
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
position: relative;
opacity: 0;
-webkit-transition: opacity 0.1s ease-in-out;
transition: opacity 0.1s ease-in-out;
}
.loaded.quizcard {
opacity: 1;
}
.quizcard--status {
position: absolute;
top: 50%;
margin-top: -30px;
z-index: 2;
width: 100%;
text-align: center;
pointer-events: none;
}
.quizcard--status i {
font-size: 100px;
opacity: 0;
-webkit-transform: scale(0.3);
transform: scale(0.3);
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
position: absolute;
width: 100px;
margin-left: -50px;
}
.quizcard_love .fa-check {
opacity: 0.7;
-webkit-transform: scale(1);
transform: scale(1);
}
.quizcard_nope .fa-remove {
opacity: 0.7;
-webkit-transform: scale(1);
transform: scale(1);
}
.quizcard--cards {
-webkit-box-flex: 1;
flex-grow: 1;
padding-top: 40px;
text-align: center;
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: end;
align-items: flex-end;
z-index: 1;
}
.quizcard--buttons {
-webkit-box-flex: 0;
flex: 0 0 100px;
text-align: center;
padding-top: 20px;
}
.quizcard--buttons button {
border-radius: 50%;
line-height: 60px;
width: 60px;
border: 0;
background: #FFFFFF;
display: inline-block;
margin: 0 8px;
background: #000;
}
.quizcard--buttons button:focus {
outline: 0;
}
.quizcard--buttons i {
font-size: 32px;
vertical-align: middle;
}
.fa-check {
color: #089404;
}
.fa-remove {
color: red;
}
.flip-card {
display: inline-block;
width: 90vw;
max-width: 400px;
height: 70vh;
text-align: center;
margin: 50px auto;
position: absolute;
-o-transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
-o-transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.do-flip {
-o-transform: rotateY(-180deg);
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.flip-card .flip-card-front, .flip-card-back{
width: 100%;
height: 100%;
position: absolute;
-o-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
z-index: 2;
-webkit-box-shadow: 5px 6px 32px 2px rgba(133,133,133,0.71);
-moz-box-shadow: 5px 6px 32px 2px rgba(133,133,133,0.71);
box-shadow: 5px 6px 32px 2px rgba(133,133,133,0.71);
}
.flip-card .flip-card-front {
background: lightgreen;
border:1px solid grey;
}
.flip-card .flip-card-back {
background: lightblue;
border: 1px solid grey;
-o-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
height: 100%;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'>
<div class="quizcard">
<div class="quizcard--cards">
<div class="flip-card">
<div class="flip-card-front"><p>Front1</p></div>
<div class="flip-card-back"><p>Back1</p><button class="next">flip</button></div>
</div>
<div class="flip-card">
<div class="flip-card-front"><p>Front2</p></div>
<div class="flip-card-back"><p>Back2</p><button class="next">flip</button></div>
</div>
<div class="flip-card">
<div class="flip-card-front"><p>Front3</p></div>
<div class="flip-card-back"><p>Back3</p><button class="next">flip</button></div>
</div>
<div class="flip-card">
<div class="flip-card-front"><p>Front4</p></div>
<div class="flip-card-back"><p>Back4</p><button class="next">flip</button></div>
</div>
<div class="flip-card">
<div class="flip-card-front"><p>Front5</p></div>
<div class="flip-card-back"><p>Back5</p><button class="next">flip</button></div>
</div>
</div>
<div class="quizcard--buttons">
<button id="nope"><i class="fa fa-remove"></i></button>
<button id="love"><i class="fa fa-check"></i></button>
</div>
</div>
While adding Events to a class in JS you should use getElementsByClassName instead of getElementById .
Try this code
document.getElementsByClassName('next').onclick = function() { document.getElementById('flip-card').classList.toggle('do-flip'); };
Related
Kindly ask for your advice making working a javascript navigation bar.
It should be supposed to:
open a page preview clicking on the link (I think to have achieve that, even though with a too long code block);
open the selected page with the second click (the first is just for the preview -- i tried with a container.classList.toggle("active"); inside each element.onclick function but didn't work)
give you the chance to open the page clicking directly on the preview (I don't have a clue how to do so)
const hamburger_menu = document.querySelector(".hamburger-menu");
const container = document.querySelector(".container");
hamburger_menu.addEventListener("click", () => {
container.classList.toggle("active");
document.getElementById("home-btn").onclick = function() {
document.getElementById("home").style.display = "block";
document.getElementById("services").style.display = "none";
document.getElementById("portfolio").style.display = "none";
document.getElementById("about").style.display = "none";
document.getElementById("contact").style.display = "none";
};
document.getElementById("services-btn").onclick = function() {
document.getElementById("services").style.display = "block";
document.getElementById("home").style.display = "none";
document.getElementById("portfolio").style.display = "none";
document.getElementById("about").style.display = "none";
document.getElementById("contact").style.display = "none";
};
document.getElementById("portfolio-btn").onclick = function() {
document.getElementById("portfolio").style.display = "block";
document.getElementById("home").style.display = "none";
document.getElementById("services").style.display = "none";
document.getElementById("about").style.display = "none";
document.getElementById("contact").style.display = "none";
};
document.getElementById("about-btn").onclick = function() {
document.getElementById("about").style.display = "block";
document.getElementById("home").style.display = "none";
document.getElementById("services").style.display = "none";
document.getElementById("portfolio").style.display = "none";
document.getElementById("contact").style.display = "none";
};
document.getElementById("contact-btn").onclick = function() {
document.getElementById("contact").style.display = "block";
document.getElementById("home").style.display = "none";
document.getElementById("services").style.display = "none";
document.getElementById("portfolio").style.display = "none";
document.getElementById("about").style.display = "none";
};
});
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
min-height: 100vh;
width: 100%;
background-color: #485461;
background-image: linear-gradient(135deg, #485461 0%, #28313b 74%);
overflow-x: hidden;
transform-style: preserve-3d;
}
.navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 100;
height: 5rem;
}
.menu {
max-width: 72rem;
height: inherit;
width: 100%;
margin: 0 auto;
padding: 0 2rem;
display: flex;
align-items: center;
color: #fff;
}
.logo {
font-size: 1.1rem;
font-weight: 600;
letter-spacing: 2px;
line-height: 4rem;
}
.logo span {
font-weight: 300;
}
.hamburger-menu {
height: 4rem;
width: 3rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: auto;
}
.bar {
width: 1.9rem;
height: 1.5px;
border-radius: 2px;
background-color: #eee;
transition: 0.5s;
position: relative;
}
.bar::before,
.bar::after {
content: "";
position: absolute;
width: inherit;
height: inherit;
background-color: #eee;
transition: 0.5s;
}
.bar::before {
transform: translateY(-9px);
}
.bar::after {
transform: translateY(9px);
}
.main {
position: relative;
width: 100%;
left: 0;
z-index: 5;
overflow: hidden;
transform-origin: left;
transform-style: preserve-3d;
transition: 0.5s;
}
header {
min-height: 100vh;
width: 100%;
background: url("../milky_way.jpg") no-repeat top center / cover;
position: relative;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(43, 51, 59, 0.8);
display: flex;
justify-content: center;
align-items: center;
}
.inner {
max-width: 50rem;
text-align: center;
color: #fff;
padding: 0 2rem;
}
.title {
font-size: 2.72rem;
margin-bottom: 1.25rem
}
.description {
font-family: "Open Sans";
margin-bottom: 3rem;
}
.btn {
font-size: 0.75rem;
margin: 1rem;
padding: 0.6rem 1.2rem;
background-color: #1179e7;
border: 2px solid #1179e7;
border-radius: 25px;
color: #fff;
background-color: transparent;
text-transform: uppercase;
cursor: pointer;
text-decoration: none;
}
.btn:hover {
animation: pulse 1s;
box-shadow: 0 0 0 2em transparent;
}
#keyframes pulse {
0% {
box-shadow: 0 0 0 0 #1179e7;
}
}
.container.active .bar {
transform: rotate(360deg);
background-color: transparent;
}
.container.active .bar::before {
transform: translateY(0) rotate(45deg);
}
.container.active .bar::after {
transform: translateY(0) rotate(-45deg);
}
.container.active .main {
animation: main-animation 0.5 ease;
cursor: pointer;
transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
}
#keyframes main-animation {
from{
transform: translate(0);
}
to{
transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
}
}
.links {
position: absolute;
width: 30%;
right: 0;
top: 0;
height: 100vh;
z-index: 2;
display: flex;
justify-content: center;
align-items: center;
}
ul {
list-style: none;
}
.links a {
text-decoration: none;
color: #bbb;
padding: 0.7rem 0;
display: inline-block;
font-size: 1rem;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
transition: 0.3s;
opacity: 0;
transform: translateY(10px);
animation: hide 0.5s forwards ease;
}
.links a:hover {
color: #fff;
}
.container.active .links a {
animation: appear 0.5s forwards ease var(--i);
}
#keyframes appear {
from{
opacity: 0;
transform: translateY(10px);
}
to{
opacity: 1;
transform: translateY(0px);
}
}
#keyframes hide {
from{
opacity: 1;
transform: translateY(0px);
}
to{
opacity: 0;
transform: translateY(10px);
}
}
.shadow {
position: absolute;
width: 100%;
height: 100vh;
top: 0;
left: 0;
transform-style: preserve-3d;
transform-origin: left;
transition: 0.5s;
background-color: white;
}
.shadow.one {
z-index: -1;
opacity: 0.15;
}
.shadow.two {
z-index: -2;
opacity: 0.1;
}
.container.active .shadow.one {
animation: shadow-one 0.6s ease-out;
transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
}
#keyframes shadow-one {
0%{
transform: translate(0);
}
5%{
transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
}
100%{
transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
}
}
.container.active .shadow.two {
animation: shadow-two 0.6s ease-out;
transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
}
#keyframes shadow-two {
0%{
transform: translate(0);
}
5%{
transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
}
100%{
transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
}
}
.container.active .main:hover + .shadow.one {
transform: perspective(1300px) rotateY(20deg) translateZ(230px) scale(0.5);
}
.container.active .main:hover {
transform: perspective(1300px) rotateY(20deg) translateZ(340px) scale(0.5);
}
#services,
#portfolio,
#about,
#contact {
display: none;
}
<div class="container">
<div class="navbar">
<div class="menu">
<div class="hamburger-menu">
<div class="bar">
</div>
</div>
</div>
</div>
<div class="main-container">
<div class="main" id="home">
<header>
<div class="overlay">
<div class="inner">
<h2 class="title">home</h2>
</div>
</div>
</header>
</div>
<div class="main" id="services">
<header>
<div class="overlay">
<div class="inner">
<h2 class="title">services</h2>
</div>
</div>
</header>
</div>
<div class="main" id="portfolio">
<header>
<div class="overlay">
<div class="inner">
<h2 class="title">portfolio</h2>
</div>
</div>
</header>
</div>
<div class="main" id="about">
<header>
<div class="overlay">
<div class="inner">
<h2 class="title">about</h2>
</div>
</div>
</header>
</div>
<div class="main" id="contact">
<header>
<div class="overlay">
<div class="inner">
<h2 class="title">contact</h2>
</div>
</div>
</header>
</div>
<div class="shadow one">
</div>
<div class="shadow two">
</div>
</div>
<div class="links">
<ul>
<li>
Home
</li>
<li>
Services
</li>
<li>
Portfolio
</li>
<li>
About
</li>
<li>
Contact
</li>
</ul>
</div>
</div>
so Im trying to make an interactive button that would be placed on the bottom of my screen and when clicked, a semicircle is created around it. this has buttons inside, so its kind of a navigation menu. Im now struggling with the math behind it. Right now, the buttons are distributed all around the circle, however i want them to only be placed in the upper part of my semicircle. This is the code i have so far:
var items = document.querySelectorAll('.menuItem');
for(var i = 0, l = items.length; i < l; i++) {
items[i].style.left = (50 - 35*Math.cos(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
items[i].style.top = (50 + 35*Math.sin(-0.5 * Math.PI - 2*(1/l)*i*Math.PI)).toFixed(4) + "%";
}
document.querySelector('.center').onclick = function(e) {
e.preventDefault(); document.querySelector('.circle').classList.toggle('open');
}
#import "https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css";
body {
/* Image source: http://wallbase.cc/wallpaper/718405 */
/* Excuse the base64 mess, imgur blocked the hotlinked image and this seemed like the fastest solution */
background: cornflowerblue url(" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAAoCAYAAABOzvzpAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOlUlEQVRo3k2aTWLj2o6DP5BHTt7dUk97C73/dbyySPSAlOoOXE7slC3+gQCO9L//839WiAyICDIAQYQAw/7bbtrmbmM35cKe9+Um1USYC8goroSfNJ+E3zS/R/xm83uJ/xzzk+L3Ej8h8ogTQhGgxErK4tahHHw7uB18ndwt7t5nB98W1eLr5Ntwd3Dv89dwF/xp+N7mW1DdfKupbm6bg5ggJDIEMplBaF5DYBuTNCa7KYss0RgoQKSCAI6KDHFlcG0iriu40nyu5OfAzxE/F/wc+JwgM0iJiAm+lYhATuTAJGERHciHaBP9vDYJiA5OiT/7c7ahgwjjalCADCW8RU2bI4Q0AQ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y7X0Q2NI7vcf3z7UWL1r8elnlFinCRF44xZi7nOFOJW75H5sNWqeOVtvetxtsK0+3M/wzP/bMk1GPAebq7E9O42r+S1h5kNURlwKWZ2O8YzVM1nxJqq7xfufQQFfEN7PM2r3Ydseezr25z1nMKgXJ4Qo0ifLhiStH6fg3o8yH+1d/+78vwNnvUx1A0FR3vs9DCZ0ekNe4fW698/tlmPO1zbN7SXq/fgwzrKuYZpi/fmqdy2rnzMz353xFjTgzu5p0PB3MzUvfejadZ10VRoZ/25gWtI0d+7VvgXlX4MlL+z7+U9/w/sgwZKH+EVWgAAAABJRU5ErkJggg==") no-repeat fixed;
background-size: cover;
}
a {
font-size: 14px;
text-decoration: none;
outline: 0;
}
.circle,
.ring {
height: 256px;
position: relative;
width: 256px;
}
.circle {
margin: 0 auto;
}
.ring {
background-color: rgba(0,0,0,0.5);
border-radius: 50%;
opacity: 0;
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-webkit-transform: scale(0.1) rotate(-270deg);
-moz-transform: scale(0.1) rotate(-270deg);
-transform: scale(0.1) rotate(-270deg);
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
.open .ring {
opacity: 1;
-webkit-transform: scale(1) rotate(0);
-moz-transform: scale(1) rotate(0);
transform: scale(1) rotate(0);
}
.center {
background-color: rgba(255,255,255,0.3);
border-radius: 50%;
border: 2px solid #ffffff;
bottom: 0;
color: white;
height: 80px;
left: 0;
line-height: 80px;
margin: auto;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 80px;
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
.open .center {
border-color: #aaaaaa;
}
.menuItem {
border-radius: 50%;
color: #eeeeee;
display: block;
height: 40px;
line-height: 40px;
margin-left: -20px;
margin-top: -20px;
position: absolute;
text-align: center;
width: 40px;
}
<div class="circle">
<div class="ring">
</div>
</div>
the end would look something like this
button mockup
Both the top and left calculations need adjusting so there isn't so much movement:
var items = document.querySelectorAll('.menuItem');
for (var i = 0, l = items.length; i < l; i++) {
items[i].style.left = (50 - 35 * Math.cos(-0.125 * Math.PI - (1 / l) * i * Math.PI)).toFixed(4) + "%";
items[i].style.top = (50 + 35 * Math.sin(-0.125 * Math.PI - (1 / l) * i * Math.PI)).toFixed(4) + "%";
}
document.querySelector('.center').onclick = function(e) {
e.preventDefault();
document.querySelector('.circle').classList.toggle('open');
}
#import "https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css";
body {
/* Image source: http://wallbase.cc/wallpaper/718405 */
/* Excuse the base64 mess, imgur blocked the hotlinked image and this seemed like the fastest solution */
background: cornflowerblue url(" data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAAoCAYAAABOzvzpAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOlUlEQVRo3k2aTWLj2o6DP5BHTt7dUk97C73/dbyySPSAlOoOXE7slC3+gQCO9L//839WiAyICDIAQYQAw/7bbtrmbmM35cKe9+Um1USYC8goroSfNJ+E3zS/R/xm83uJ/xzzk+L3Ej8h8ogTQhGgxErK4tahHHw7uB18ndwt7t5nB98W1eLr5Ntwd3Dv89dwF/xp+N7mW1DdfKupbm6bg5ggJDIEMplBaF5DYBuTNCa7KYss0RgoQKSCAI6KDHFlcG0iriu40nyu5OfAzxE/F/wc+JwgM0iJiAm+lYhATuTAJGERHciHaBP9vDYJiA5OiT/7c7ahgwjjalCADCW8RU2bI4Q0AQNkwBFkBhIQML1guk0HtE0f0Z4UYCGZxKTgRPBJuAI+F/wE/Fzm9yN+Uvxc5ucEP5e4TnBC831PAkhugiCRDmFx+6AS4ZiKtzj+W+1T8O0gS5yG7y3U5k8JqSd4hGkssAK3OZKImGor4ESSR0SIE0xiNjlGNHrHwZ7fcSCKkEnESfNJ8xPB75lK/17wc03b/x74/QSfA5+T5AkingQERZA6kwQdqoN0khbVQXdwtWYMin0W15sEc46IG1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353xFjTgzu5p0PB3MzUvfejadZ10VRoZ/25gWtI0d+7VvgXlX4MlL+z7+U9/w/sgwZKH+EVWgAAAABJRU5ErkJggg==") no-repeat fixed;
background-size: cover;
}
a {
font-size: 14px;
text-decoration: none;
outline: 0;
}
.circle,
.ring {
height: 256px;
position: relative;
width: 256px;
}
.circle {
margin: 0 auto;
}
.ring {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 50%;
opacity: 0;
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-webkit-transform: scale(0.1) rotate(-270deg);
-moz-transform: scale(0.1) rotate(-270deg);
transform: scale(0.1) rotate(-270deg);
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
position: relative;
}
.open .ring {
opacity: 1;
-webkit-transform: scale(1) rotate(0);
-moz-transform: scale(1) rotate(0);
transform: scale(1) rotate(0);
}
.center {
background-color: rgba(255, 255, 255, 0.3);
border-radius: 50%;
border: 2px solid #ffffff;
bottom: 0;
color: white;
height: 80px;
left: 0;
line-height: 80px;
margin: auto;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 80px;
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
.open .center {
border-color: #aaaaaa;
}
.menuItem {
border-radius: 50%;
color: #eeeeee;
display: block;
height: 40px;
line-height: 40px;
margin-left: -20px;
margin-top: -20px;
position: absolute;
text-align: center;
width: 40px;
}
<div class="circle">
<div class="ring">
</div>
</div>
I'm trying to turn my menu into an X shape with animations. Here's a video of what it currently looks like.
Video
I want to make it more smooth and actually make the cross symmetrical.
I have create a code snippet with all the relevant code below.
const NAV_BTN = document.querySelector('.navmenu');
const NL_1 = document.querySelector('.l1');
const NL_2 = document.querySelector('.l2');
const NL_3 = document.querySelector('.l3');
NAV_BTN.addEventListener('click', () => {
navToClose();
});
const navToClose = () => {
NL_1.style.animation = '0.5s l1Close forwards';
NL_2.style.animation = '0.5s l2Close forwards';
NL_3.style.animation = '0.5s l3Close forwards';
};
.container{
height: 200px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.navmenu {
transition: all 0.5s;
}
.nline{
width: 40px;
height: 4px;
border-radius: 0.5px;
background-color: white;
margin-top: 5px;
margin-bottom: 5px;
}
.l1 {
width: 20px;
transition: all 0.5s;
}
.l3 {
width: 20px;
transition: all 0.5s;
margin-left: auto;
}
.navmenu:hover>.l1,
.navmenu:hover>.l3 {
width: 40px;
}
.navmenu:hover {
opacity: 0.5;
cursor: pointer;
}
/* ANIMATIONS */
#keyframes l1Close{
0%{
transform: rotate(0deg);
margin: 0;
}
100%{
transform: translate(0,0) rotate(-45deg);
width: 40px;
}
}
#keyframes l2Close{
0%{
opacity: 1;
}
100%{
opacity: 0;
}
}
#keyframes l3Close{
0%{
transform: rotate(0deg);
}
100%{
transform: translate(0,0) rotate(45deg);
width: 40px;
}
}
<div class="container">
<div class="navmenu">
<div class="nline l1"></div>
<div class="nline l2"></div>
<div class="nline l3"></div>
</div>
</div>
I would appreciate any help, and will reply if you have any questions.
Thanks.
The following code should be close enough to the solution you are aiming for. The transition can be modified according to your needs and the seconds must be adapted accordingly.
.container{
height: 200px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.navmenu {
transition: all 0.8s;
}
.nline{
width: 40px;
height: 4px;
border-radius: 0.5px;
background-color: white;
margin-top: 5px;
margin-bottom: 5px;
}
.l1 {
width: 20px;
transition: all 0.5s linear;
}
.l2 {
width: 40px;
transition: all 0.3s linear;
}
.l3 {
width: 20px;
transition: all 0.5s linear;
margin-left: auto;
}
.navmenu:hover>.l1 {
width: 40px;
position: relative;
top: 7px;
transform: rotate(-45deg);
}
.navmenu:hover>.l3 {
width: 40px;
position: relative;
top: -7px;
transform: rotate(45deg);
}
.navmenu:hover>.l2 {
height: 1.5px;
opacity:0;
}
.navmenu:hover {
opacity: 0.5;
cursor: pointer;
}
<div class="container">
<div class="navmenu">
<div class="nline l1"></div>
<div class="nline l2"></div>
<div class="nline l3"></div>
</div>
</div>
I've written some JavaScript code that almost works the way I want it to, but I need some help figuring out how to make it work the way I need it to.
I want to change the colour of a fixed navigation element (hamburger) when it encounters a section with the class of white.Right now this is accomplished by adding a class of darker to that nav element.
What I can't figure out is how to have the darker class removed when I scroll past an element that no longer has the class of white. Any help is much appreciated!
Thanks in advance! :)
Code pen demo
The code is as follows: (Maybe not showing as expected here in SO, better in Codepen)
$(document).ready(function(){
$('#hamburger').click(function(){
$(this).toggleClass('open');
});
});
$(document).ready(function () {
var change = $('.change');
$(window).scroll(function () {
var y = $(this).scrollTop();
var z = $('.white').offset().top;
if (y >= z) {
change.addClass('darker');
}
else {
change.removeClass('darker');
}
});
});
//Variables
$grey-darker: hsl(0, 0%, 21%);
$grey: hsl(0, 0%, 48%);
$white: hsl(0, 0%, 100%);
$bold: 900;
//Formatting
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: sans-serif;
letter-spacing: -1.5px;
}
h1 {
color: $white;
font-size: 7em;
font-weight: $bold;
}
//Navigation/
.navigation {
display:flex;
vertical-align:top;
width: 100%;
height: 76px;
position: fixed;
}
//Hamburger --> This should change from white & blue depending on background color
#hamburger {
width: 30px;
height: 20px;
margin-left: auto;
align-self: center;
margin-right: 30px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out, ;
transition-delay: background 0.4s;
cursor: pointer;
z-index: 5;
}
#hamburger span {
display: block;
position: absolute;
height: 3px;
width: 100%;
background: $white;
border-radius: 9px;
opacity: 1;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out, ;
transition-delay: background 0.4s;
}
#hamburger span.change.darker{
background: Blue;
}
#hamburger span:nth-child(1) {
top: 0px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#hamburger span:nth-child(2) {
top: 6px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#hamburger span:nth-child(3) {
top: 12px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
#hamburger.open span:nth-child(1) {
background:white;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
top: 0px;
left: 5px;
}
#hamburger.open span:nth-child(2) {
width: 0%;
opacity: 0;
}
#hamburger.open span:nth-child(3) {
background:white;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
top: 22px;
left: 5px;
}
//Main
.container-fullpage {
display: flex;
flex-direction: row;
flex-flow: row wrap;
align-items: center;
justify-content: space-around;
height: 100vh;
width: 100vw;
}
.sectionOne {
background: blue;
}
.sectionTwo{
color: blue;
background: $white;
}
.sectionTwo h1 {
color: blue;
}
.sectionThree{
background: blue;
}
.sectionFour{
background: $white;
}
.sectionFour h1 {
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header class="header">
<nav class="navigation">
<div class="hamburger" id="hamburger">
<span class="change"></span>
<span class="change"></span>
<span class="change"></span>
</div>
</nav>
</header>
<main>
<div class="container-fullpage sectionOne">
<h1 class="home">First Section</h1>
</div>
<div class="container-fullpage sectionTwo white">
<h1>Second Section</h1>
</div>
<div class="container-fullpage sectionThree">
<h1>Third Section</h1>
</div>
<div class="container-fullpage sectionFour white">
<h1>Fourth Section</h1>
</div>
</main>
I think this is the javascript code that will do what you want:
$(document).ready(function(){
$('#hamburger').click(function(){
$(this).toggleClass('open');
});
});
$(document).ready(function () {
var change = $('.change');
$(window).scroll(function () {
var top1 = change.offset().top;
var bottom1 = change.offset().top + change.outerHeight(true);
var overlapsWhite = false;
$('.white').each(function() {
var top2 = $(this).offset().top;
var bottom2 = $(this).offset().top + $(this).outerHeight(true);
if (top1 >= top2 && bottom2 >= bottom1){
overlapsWhite = true;
return false;
}
});
if (overlapsWhite) {
change.addClass('darker');
}
else {
change.removeClass('darker');
}
});
});
Check on Code pen
I have made a product block with the option to see on hover a nice effect but i would like to see the hover effect which I am seeing on hover to be seen on click of the div but I don't know how I can achieve that.
The only thing I want is to have it completely in css/sass or Javascript if it cannot be done with Javascript or css/sass then jQuery is ok.
body {
width: 100%;
height: 100%;
background-color: #c8cfdc;
color: #363636;
font-family: 'Roboto', sans-serif;
}
.blocks_container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
padding: 20px 0;
width: 90%;
margin: 0 auto;
max-width: 1170px;
}
.block {
background-color: #fff;
cursor: pointer;
margin-bottom: 20px;
}
.product_block {
width: 31%;
overflow: hidden;
position: relative;
height: 340px;
-webkit-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.product_block .product_header {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 55px;
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
-webkit-transition: -webkit-transform 0.43s cubic-bezier(0.32, 1.259, 0.375, 1.15);
transition: -webkit-transform 0.43s cubic-bezier(0.32, 1.259, 0.375, 1.15);
transition: transform 0.43s cubic-bezier(0.32, 1.259, 0.375, 1.15);
transition: transform 0.43s cubic-bezier(0.32, 1.259, 0.375, 1.15), -webkit-transform 0.43s cubic-bezier(0.32, 1.259, 0.375, 1.15);
}
.product_block .product_header .product_heart {
float: left;
margin-top: 15px;
padding-left: 30px;
}
.product_block .product_header .product_heart img {
width: 20px;
height: 20px;
}
.product_block .product_header .product_tag {
position: absolute;
top: 15px;
left: 50%;
text-align: center;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
color: #fff;
text-transform: uppercase;
font-family: 'Ropa Sans', sans-serif;
background-color: #3b4068;
padding: 4px 15px;
border-radius: 0.8em;
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.product_block .product_header .product_shop {
float: right;
margin-top: 15px;
padding-right: 30px;
}
.product_block .product_header .product_shop img {
width: 20px;
height: 20px;
}
.product_block .product_img {
margin: 0 auto;
width: 95%;
height: 260px;
background-size: contain;
background-position: 50% 80%;
background-repeat: no-repeat;
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: -webkit-transform 0.3s ease-in-out;
transition: -webkit-transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out, -webkit-transform 0.3s ease-in-out;
transition: all 900ms ease;
}
.product_block .product_info {
transform: translate(0px, 200px);
text-align: center;
padding-top: 20px;
}
.product_block .product_info .product_title {
font-size: 16px;
font-family: 'Ropa Sans', sans-serif;
text-transform: uppercase;
margin-bottom: 5px;
}
.product_block .product_info .product_subtitle {
font-size: 12px;
font-weight: 300;
letter-spacing: 1px;
color: #999;
margin: 0;
margin-bottom: 15px;
}
.product_block .product_info .product_price {
font-family: 'Ropa Sans', sans-serif;
font-size: 15px;
text-transform: uppercase;
font-weight: 700;
}
.product_block .product_info .product_price span {
text-decoration: line-through;
color: #fc7070;
padding-left: 9px;
}
.product_block:hover {
transition: all 300ms ease;
background-color: #3b4068;
color: #fff;
}
.product_block:hover .product_header {
-webkit-transform: translateY(0);
transform: translateY(0);
}
.product_block:hover .product_header .product_tag {
background-color: #fff;
color: #3b4068;
}
.product_block:hover .product_img {
transition: all 300ms ease-in-out;
-webkit-transform: scale(1.03);
transform: scale(1.03);
background-position: 30% 30%;
width: 40%;
-ms-transform: rotate(20deg);
/* IE 9 */
-webkit-transform: rotate(20deg);
/* Safari */
transform: rotate(20deg);
}
.product_block:hover .product_info {
transition: all 300ms ease;
transform: translate(0px, -150px);
text-align: center;
padding-top: 20px;
}
<div class="blocks_container">
<div class="block product_block rem" id="red">
<div class="product_header">
<div class="product_heart"> <img src="http://calleriphotographer.it/loving.svg"/></div>
<!-- <div class="product_tag">Waffle</div> -->
<div class="product_shop"><img src="http://calleriphotographer.it/cart.svg"/></div>
</div>
<div class="product_img" style="background-image: url('http://calleriphotographer.it/nike.png')"></div>
<div class="product_info">
<h3 class="product_title">nike</h3>
<h5 class="product_subtitle">Air Max Tavas SD</h5>
<p class="product_price">$160.00<span>$200.00</span></p>
</div>
</div>
</div>
If you want to edit it in codepen with sass click below
my codepen link
You just need an active state for you .product_block element
CSS
.product_block.active:hover {
transition: all 300ms ease;
background-color: #3b4068;
color: #fff;
}
.product_block.active:hover .product_header {
-webkit-transform: translateY(0);
transform: translateY(0);
}
.product_block.active:hover .product_header .product_tag {
background-color: #fff;
color: #3b4068;
}
.product_block.active:hover .product_img {
transition: all 300ms ease-in-out;
-webkit-transform: scale(1.03);
transform: scale(1.03);
background-position: 30% 30%;
width: 40%;
-ms-transform: rotate(20deg);
/* IE 9 */
-webkit-transform: rotate(20deg);
/* Safari */
transform: rotate(20deg);
}
.product_block.active:hover .product_info {
transition: all 300ms ease;
transform: translate(0px, -150px);
text-align: center;
padding-top: 20px;
}
JS
var elem = document.querySelector('.product_block');
elem.addEventListener("click", function(){
this.classList.add('active');
})
P.S. JSFiddle
Toggle logic
var elem = document.querySelector('.product_block');
elem.addEventListener("click", function(){
if(this.classList.contains('active')) {
this.classList.remove('active');
} else {
this.classList.add('active');
}
})
You need to query all items and then iterate over them
Like that:
var elems = document.querySelectorAll('.product_block');
for(var i = 0; i < elems.length; i = i +1) {
elems[i].addEventListener("click", function(){
if(this.classList.contains('active')) {
this.classList.remove('active');
} else {
this.classList.add('active');
}
})
}