html,body{
height: 100%;
}
body{
margin: 0;
background-color: #0f0f0f;
color: white;
font-family: 'Ubuntu', sans-serif;
display: grid;
grid-template-columns: 1fr 8fr;
}
header{
height: 5vh;
grid-column: 1/3;
grid-row:1/2 ;
background-color: black;
z-index: 2;
display: block;
}
section{
position: relative;
display: flex;
flex-direction: column;
min-height: 300px;
}
.TopContent{
height: 70vh;
grid-column: 1/3;
grid-row:2/3 ;
background-color: white;
z-index: 1;
}
.Content{
grid-column: 1/3;
}
.TopNavigation{
display: flex;
flex-direction: column;
}
.TopNavBtn{
background-color: #000000;
text-align: center;
vertical-align: middle;
color: white;
margin: 0px;
border: 0px;
height: 5vh;
width: 90px;
font-size: 25px;
transition-duration: 0.3s;
}
.TopNavBtn:hover{
height: 7vh;
font-size: 27px;
background-color: #272727;
font-weight: bold;
}
.Navigation{
grid-column: 1/2;
background-color: #0f0f0f;
}
.Divider{
aspect-ratio: 900/300;
width: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.Grad1
{
background-image: url("img/svg/Grad1.svg");
}
.Grad2
{
background-image: url("img/svg/Grad2.svg");
}
.Grad3
{
background-image: url("img/svg/Grad3.svg");
}
.Grad4
{
background-image: url("img/svg/Grad4.svg");
}
.RGrad1
{
background-image: url("img/svg/RGrad1.svg");
}
.RGrad2
{
background-image: url("img/svg/RGrad2.svg");
}
.RGrad3
{
background-image: url("img/svg/RGrad3.svg");
}
.RGrad4
{
background-image: url("img/svg/RGrad4.svg");
}
.b{
background-color: #015657;
}
.g{
background-color: #303030;
}
.w{
background-color: white;
}
#keyframes logo {
0%{background-image: url("img/grass.png");}
25% {background-image: url("img/dia.png");}
50%{background-image: url("img/spawner1.png");}
75%{background-image: url("img/oak1.png");}
100%{background-image: url("img/grass.png");}
}
.logo{
background-image: url("grass.png");
background-repeat: no-repeat;
width: 200px;
height: 200px;
animation-name:logo;
animation-duration: 10s;
animation-play-state:paused ;
animation-iteration-count:infinite ;
align-items: center;
align-content: center;
margin: auto;
}
.logo:hover{
animation-play-state:running ;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="Project.css"/>
<title>Document</title>
</head>
<body >
<header id="TNav">
<nav class="TopNavigation" id="xdd">
<button class="TopNavBtn">xd</button>
</nav>
</header>
<article class="TopContent">
<div class="logo"></div>
</article>
<nav class="Navigation">
</nav>
<article class="Content">
<section class=" b" >
<p>Aliquid, ab? Quod nulla aliquam libero placeat et distinctio fugit maiores quisquam odit illo repellat, provident modi. Placeat, maiores facere, ut dolorem assumenda amet alias natus, expedita sit mollitia minima?</p>
</section>
<div class="Divider Grad1" ></div>
<section class=" g">
<p>Aliquid, ab? Quod nulla aliquam libero placeat et distinctio fugit maiores quisquam odit illo repellat, provident modi. Placeat, maiores facere, ut dolorem assumenda amet alias natus, expedita sit mollitia minima?</p>
</section>
<div class="Divider RGrad1" ></div>
<section class="b">
<p>Tenetur mollitia esse omnis rem voluptatum, quaerat, delectus nulla quasi similique deleniti tempora a libero ducimus, sit asperiores fugiat temporibus error. Alias consectetur sit odio? Praesentium, reiciendis dicta. Ducimus, consequatur.</p>
</section>
<div class="Divider Grad2" ></div>
<section class="g">
<p>Debitis sed ullam assumenda quasi! Quibusdam, laudantium minus cum delectus quasi facilis, quam amet alias ex, voluptatibus cumque ratione praesentium laborum sint nemo eaque sunt tempora qui ad odio consequatur!</p>
</section >
<div class="Divider RGrad2" ></div>
<section class="b">
<p>Autem ratione tempora officiis reprehenderit, voluptatem rem sit quas veritatis! Aspernatur rerum nam architecto ex voluptates earum illo rem quia, culpa quaerat fuga voluptatibus impedit eaque iste sint nostrum facilis!</p>
</section>
<div class="Divider Grad3" ></div>
<section class="g">
<p>Autem ratione tempora officiis reprehenderit, voluptatem rem sit quas veritatis! Aspernatur rerum nam architecto ex voluptates earum illo rem quia, culpa quaerat fuga voluptatibus impedit eaque iste sint nostrum facilis!</p>
</section>
<div class="Divider RGrad3" ></div>
<section class="b">
<p>Autem ratione tempora officiis reprehenderit, voluptatem rem sit quas veritatis! Aspernatur rerum nam architecto ex voluptates earum illo rem quia, culpa quaerat fuga voluptatibus impedit eaque iste sint nostrum facilis!</p>
</section>
</article>
<script>
let NavBar = document.getElementById("xdd");
let bound = NavBar.getBoundingClientRect();
window.onscroll= function (){
console.log("scrolled")
console.log(bound)
if(bound.top >=0)
{
}
else
{
console.log("isnt")
}
}
// to check if the DOM is loaded
document.addEventListener("DOMContentLoaded", (event) =>{
console.log("ready");
})
</script>
</body>
</html>
I am trying to detected whether an Elemnt is inside the Viewport. When i looked this up, i was directed to usimg getBoundingClientRect to get its location relative to the Viewport.
However, when i tried implementing this solution, it didnt work, as this always returned a DOMRect with the x,y, top and left values being 0 and the others staying constant no matter where i scroll.
The html element(s) i want to get the location of:
<header id="TNav">
<nav class="TopNavigation" id="xdd">
<button class="TopNavBtn">xd</button>
</nav>
</header>
Its CSS:
header{
height: 5vh;
grid-column: 1/3;
grid-row:1/2 ;
background-color: black;
z-index: 2;
display: block;
}
.TopNavigation{
display: flex;
flex-direction: column;
}
The JS code:
let NavBar = document.getElementById("xdd");
let bound = NavBar.getBoundingClientRect();
window.onscroll= function (){
console.log("scrolled")
console.log(bound)
if(bound.top >=0)
{
}
else
{
console.log("isnt")
}
}
// to check if the DOM is loaded
document.addEventListener("DOMContentLoaded", (event) =>{
console.log("ready");
})
the code is implemented at the very bottom of the <body>.
I tried testing if the DOM is loaded and changing which element i read the location of.
Here is what the the getBoundingClientRect() returns:
Thanks to user Unmitigated, i now have the answer:
The let bound = NavBar.getBoundingClientRect had to be moved inside the window.onscroll event handler, like so:
<script>
let NavBar = document.getElementById("xdd");
window.onscroll= function (){
let bound = NavBar.getBoundingClientRect();
console.log("scrolled")
console.log(bound)
if(bound.top >=0)
{
}
else
{
console.log("isnt")
}
}
// to check if the DOM is loaded
document.addEventListener("DOMContentLoaded", (event) =>{
console.log("ready");
})
</script>
Related
When I open menu in smaller resolution(mobile resolution) and click on some link from the menu its not closing, its still there the menu. Can you help me? I think there is missing something in js code but I don't know what I can write more to close menu after clicking on the link from the menu.
const body = document.querySelector("body");
const navbar = document.querySelector(".navbar");
const menuBtn = document.querySelector(".menu-btn");
const cancelBtn = document.querySelector(".cancel-btn");
menuBtn.onclick = () => {
navbar.classList.add("show");
menuBtn.classList.add("hide");
body.classList.add("disabled");
}
cancelBtn.onclick = () => {
body.classList.remove("disabled");
navbar.classList.remove("show");
menuBtn.classList.remove("hide");
}
window.onscroll = () => {
this.scrollY > 20 ? navbar.classList.add("sticky") : navbar.classList.remove("sticky");
}
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection {
background: rgb(0, 123, 255, 0.3);
}
.content {
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
.navbar {
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
}
.navbar.sticky {
background: #1b1b1b;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.1);
}
.navbar .content {
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list {
display: inline-flex;
}
.menu-list li {
list-style: none;
}
.menu-list li a {
color: #fff;
font-size: 18px;
font-weight: 500;
margin-left: 25px;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover {
color: #007bff;
}
.banner {
background: url("banner.jpg") no-repeat;
height: 100vh;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
.about {
padding: 30px 0;
}
.about .title {
font-size: 38px;
font-weight: 700;
}
.about p {
padding-top: 20px;
text-align: justify;
}
.icon {
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn {
position: absolute;
right: 30px;
top: 20px;
}
#media (max-width: 1230px) {
.content {
padding: 0 60px;
}
}
#media (max-width: 1100px) {
.content {
padding: 0 40px;
}
}
#media (max-width: 900px) {
.content {
padding: 0 30px;
}
}
#media (max-width: 868px) {
body.disabled {
overflow: hidden;
}
.icon {
display: block;
}
.icon.hide {
display: none;
}
.navbar .menu-list {
position: fixed;
height: 100vh;
width: 100%;
max-width: 400px;
left: -100%;
top: 0px;
display: block;
padding: 40px 0;
text-align: center;
background: #222;
transition: all 0.3s ease;
}
.navbar.show .menu-list {
left: 0%;
}
.navbar .menu-list li {
margin-top: 45px;
}
.navbar .menu-list li a {
font-size: 23px;
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.navbar.show .menu-list li a {
margin-left: 0px;
}
}
#media (max-width: 380px) {
.navbar .logo a {
font-size: 27px;
}
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Navigation Bar | CodingNepal</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>
<body>
<nav class="navbar">
<div class="content">
<div class="logo">
CodingNepal
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Features</li>
<li>Contact</li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
<div class="banner"></div>
<div class="about">
<div class="content">
<div class="title">Responsive Sticky Navigation Menu Bar on Scroll using HTML CSS & JavaScript</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo impedit atque consequatur! Iusto distinctio temporibus repellendus labore odit adipisci harum ipsa beatae natus, eum eius, hic aperiam odio! Quasi molestias magnam illo voluptatem iusto
ipsam blanditiis, tempore cumque reiciendis quaerat vero tenetur, sequi dolores libero voluptas vitae voluptate placeat dolorum modi ipsa nisi repellat facilis aliquam asperiores. Aut nam repellat harum quas saepe dolorum voluptates ratione, itaque
consectetur explicabo a facilis rem mollitia maxime repudiandae fuga reprehenderit, odio cum incidunt labore molestiae quis non perferendis ipsam. Illum, in, deserunt. Ipsa.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit hic excepturi nobis id, eos dolor libero, nam assumenda, at culpa quos perspiciatis ratione ea modi! Natus sapiente a, explicabo sit quisquam eligendi esse provident eos enim doloremque
blanditiis aut placeat veniam, libero nostrum quae. Ipsam, iste reprehenderit minima accusantium illo dolorem recusandae, ipsa autem quidem reiciendis a mollitia sit tenetur.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint doloremque perspiciatis voluptate ducimus reiciendis rem expedita voluptatibus dicta harum, quo, aspernatur maiores possimus officia quod? Aliquid molestiae illo sequi, tempora perferendis
at incidunt nam porro voluptatibus, iste aperiam blanditiis adipisci ducimus repellendus distinctio nostrum ipsum! Voluptas facilis cum, atque tempora magnam beatae sequi! Doloribus expedita, cupiditate quo quod nemo aliquam, mollitia cum ea nam
ullam soluta temporibus! Repudiandae incidunt consequatur distinctio deleniti obcaecati sit facilis unde, quisquam veniam ad doloribus!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet veniam error deleniti cum beatae non assumenda illum est dolores, possimus suscipit quibusdam eveniet id fuga dolore unde modi, sapiente voluptas. Mollitia veritatis explicabo cumque
enim quia voluptates provident totam perferendis excepturi animi assumenda optio minus laudantium eveniet possimus amet blanditiis dolore in fuga atque, earum officia tempora quam similique est.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque ad sunt distinctio quidem incidunt cupiditate sequi deleniti, corrupti officia nam veritatis facilis veniam dolorum enim nisi ipsum dolor rem! Doloribus, eaque odit voluptatem iste
laboriosam provident facere quo. Cum repellat pariatur, error ratione repellendus nisi quam culpa tempora facere in atque nesciunt, magni est aliquid unde soluta optio! Dolore pariatur, quaerat quo in cupiditate deleniti exercitationem. Facilis
suscipit corporis unde aut minima nihil, eum molestias itaque, tenetur, beatae ipsa at!</p>
</div>
</div>
</body>
You need to close the menu on link click as well as cancel. I've created a function for that to avoid duplication.
const body = document.querySelector("body");
const navbar = document.querySelector(".navbar");
const menuBtn = document.querySelector(".menu-btn");
const cancelBtn = document.querySelector(".cancel-btn");
const menuLinks = document.querySelectorAll('.menu-list li a');
const closeMenu = () => {
body.classList.remove("disabled");
navbar.classList.remove("show");
menuBtn.classList.remove("hide");
};
menuBtn.onclick = () => {
navbar.classList.add("show");
menuBtn.classList.add("hide");
body.classList.add("disabled");
};
cancelBtn.onclick = () => {
closeMenu();
};
menuLinks.forEach(link => {
link.onclick = () => {
closeMenu();
};
});
window.onscroll = () => {
this.scrollY > 20 ? navbar.classList.add("sticky") : navbar.classList.remove("sticky");
};
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection {
background: rgb(0, 123, 255, 0.3);
}
.content {
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
.navbar {
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
}
.navbar.sticky {
background: #1b1b1b;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.1);
}
.navbar .content {
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list {
display: inline-flex;
}
.menu-list li {
list-style: none;
}
.menu-list li a {
color: #fff;
font-size: 18px;
font-weight: 500;
margin-left: 25px;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover {
color: #007bff;
}
.banner {
background: url("banner.jpg") no-repeat;
height: 100vh;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
.about {
padding: 30px 0;
}
.about .title {
font-size: 38px;
font-weight: 700;
}
.about p {
padding-top: 20px;
text-align: justify;
}
.icon {
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn {
position: absolute;
right: 30px;
top: 20px;
}
#media (max-width: 1230px) {
.content {
padding: 0 60px;
}
}
#media (max-width: 1100px) {
.content {
padding: 0 40px;
}
}
#media (max-width: 900px) {
.content {
padding: 0 30px;
}
}
#media (max-width: 868px) {
body.disabled {
overflow: hidden;
}
.icon {
display: block;
}
.icon.hide {
display: none;
}
.navbar .menu-list {
position: fixed;
height: 100vh;
width: 100%;
max-width: 400px;
left: -100%;
top: 0px;
display: block;
padding: 40px 0;
text-align: center;
background: #222;
transition: all 0.3s ease;
}
.navbar.show .menu-list {
left: 0%;
}
.navbar .menu-list li {
margin-top: 45px;
}
.navbar .menu-list li a {
font-size: 23px;
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.navbar.show .menu-list li a {
margin-left: 0px;
}
}
#media (max-width: 380px) {
.navbar .logo a {
font-size: 27px;
}
}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Navigation Bar | CodingNepal</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>
<body>
<nav class="navbar">
<div class="content">
<div class="logo">
CodingNepal
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Features</li>
<li>Contact</li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
<div class="banner"></div>
<div class="about">
<div class="content">
<div class="title">Responsive Sticky Navigation Menu Bar on Scroll using HTML CSS & JavaScript</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo impedit atque consequatur! Iusto distinctio temporibus repellendus labore odit adipisci harum ipsa beatae natus, eum eius, hic aperiam odio! Quasi molestias magnam illo voluptatem iusto
ipsam blanditiis, tempore cumque reiciendis quaerat vero tenetur, sequi dolores libero voluptas vitae voluptate placeat dolorum modi ipsa nisi repellat facilis aliquam asperiores. Aut nam repellat harum quas saepe dolorum voluptates ratione, itaque
consectetur explicabo a facilis rem mollitia maxime repudiandae fuga reprehenderit, odio cum incidunt labore molestiae quis non perferendis ipsam. Illum, in, deserunt. Ipsa.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit hic excepturi nobis id, eos dolor libero, nam assumenda, at culpa quos perspiciatis ratione ea modi! Natus sapiente a, explicabo sit quisquam eligendi esse provident eos enim doloremque
blanditiis aut placeat veniam, libero nostrum quae. Ipsam, iste reprehenderit minima accusantium illo dolorem recusandae, ipsa autem quidem reiciendis a mollitia sit tenetur.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint doloremque perspiciatis voluptate ducimus reiciendis rem expedita voluptatibus dicta harum, quo, aspernatur maiores possimus officia quod? Aliquid molestiae illo sequi, tempora perferendis
at incidunt nam porro voluptatibus, iste aperiam blanditiis adipisci ducimus repellendus distinctio nostrum ipsum! Voluptas facilis cum, atque tempora magnam beatae sequi! Doloribus expedita, cupiditate quo quod nemo aliquam, mollitia cum ea nam
ullam soluta temporibus! Repudiandae incidunt consequatur distinctio deleniti obcaecati sit facilis unde, quisquam veniam ad doloribus!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet veniam error deleniti cum beatae non assumenda illum est dolores, possimus suscipit quibusdam eveniet id fuga dolore unde modi, sapiente voluptas. Mollitia veritatis explicabo cumque
enim quia voluptates provident totam perferendis excepturi animi assumenda optio minus laudantium eveniet possimus amet blanditiis dolore in fuga atque, earum officia tempora quam similique est.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque ad sunt distinctio quidem incidunt cupiditate sequi deleniti, corrupti officia nam veritatis facilis veniam dolorum enim nisi ipsum dolor rem! Doloribus, eaque odit voluptatem iste
laboriosam provident facere quo. Cum repellat pariatur, error ratione repellendus nisi quam culpa tempora facere in atque nesciunt, magni est aliquid unde soluta optio! Dolore pariatur, quaerat quo in cupiditate deleniti exercitationem. Facilis
suscipit corporis unde aut minima nihil, eum molestias itaque, tenetur, beatae ipsa at!</p>
</div>
</div>
</body>
I've just included a button on the bottom right of the site to allow users to go back to the top of the page but it seems to have cancelled out my navbar from hiding when the user scrolls. I've been looking at it all morning and would really appreciate a fresh pair of eyes to look at it, any help would be great!
Thanks.
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("navigation").style.top = "0";
} else {
document.getElementById("navigation").style.top = "-70px";
}
prevScrollpos = currentScrollPos;
}
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
nav {
z-index: 99;
box-sizing: border-box;
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 20px 60px;
text-align: center;
background-color: white;
font-size: 18px;
letter-spacing: 1px;
transition: top 0.3s;
border-bottom: #f1f1f1 2px solid;
}
nav a:first-child {
float: left;
}
.main-nav {
text-decoration: none;
display: inline-block;
float: right;
text-transform: uppercase;
color: #adb3c1;
padding: 1px 0;
margin: 0 10px;
transition: all 0.15s ease-in-out;
z-index: 10;
}
#navigation a:hover {
color: blue;
transition: 0.5s;
}
.fa-long-arrow-alt-up {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99;
border: none;
outline: none;
background: none;
color: black;
cursor: pointer;
padding: 15px;
font-size: 18px;
}
#myBtn:hover {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<title>Hector's Portfolio</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/javascript.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="layout-portfolio">
<nav id="navigation">
<a data-scroll class="main-nav" class="nav-hover" href="#home">Home</a>
<a data-scroll class="main-nav" class="nav-hover" href="#contact">Contact</a>
<a data-scroll class="main-nav" class="nav-hover" href="#about">About</a>
<a data-scroll class="main-nav" class="nav-hover" href="#projects">Projects</a>
</nav>
<!-- Button to go to top -->
<button onclick="topFunction()" id="myBtn" class="fas fa-long-arrow-alt-up"></button>
</body>
</html>
window.onscroll can be set in one exemplary only, when you set it a second time, it replaces the first.
Solution: put all your code in the same function (I added scrollFunction(); to the first, but that can be the contrary):
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("navigation").style.top = "0";
} else {
document.getElementById("navigation").style.top = "-70px";
}
prevScrollpos = currentScrollPos;
scrollFunction();
}
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
nav {
z-index: 99;
box-sizing: border-box;
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 20px 60px;
text-align: center;
background-color: white;
font-size: 18px;
letter-spacing: 1px;
transition: top 0.3s;
border-bottom: #f1f1f1 2px solid;
}
nav a:first-child {
float: left;
}
.main-nav {
text-decoration: none;
display: inline-block;
float: right;
text-transform: uppercase;
color: #adb3c1;
padding: 1px 0;
margin: 0 10px;
transition: all 0.15s ease-in-out;
z-index: 10;
}
#navigation a:hover {
color: blue;
transition: 0.5s;
}
.fa-long-arrow-alt-up {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99;
border: none;
outline: none;
background: none;
color: black;
cursor: pointer;
padding: 15px;
font-size: 18px;
}
#myBtn:hover {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<title>Hector's Portfolio</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/javascript.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="layout-portfolio">
<nav id="navigation">
<a data-scroll class="main-nav" class="nav-hover" href="#home">Home</a>
<a data-scroll class="main-nav" class="nav-hover" href="#contact">Contact</a>
<a data-scroll class="main-nav" class="nav-hover" href="#about">About</a>
<a data-scroll class="main-nav" class="nav-hover" href="#projects">Projects</a>
</nav>
<div style="height: 700px;"></div>
<!-- Button to go to top -->
<button onclick="topFunction()" id="myBtn" class="fas fa-long-arrow-alt-up"></button>
</body>
</html>
The issue here is that the second onscroll overrides the first one.
So, you can move the code to single function. I have updated the code below:
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("navigation").style.top = "0";
} else {
document.getElementById("navigation").style.top = "-70px";
}
prevScrollpos = currentScrollPos;
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
nav {
z-index: 99;
box-sizing: border-box;
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 20px 60px;
text-align: center;
background-color: white;
font-size: 18px;
letter-spacing: 1px;
transition: top 0.3s;
border-bottom: #f1f1f1 2px solid;
}
nav a:first-child {
float: left;
}
.main-nav {
text-decoration: none;
display: inline-block;
float: right;
text-transform: uppercase;
color: #adb3c1;
padding: 1px 0;
margin: 0 10px;
transition: all 0.15s ease-in-out;
z-index: 10;
}
#navigation a:hover {
color: blue;
transition: 0.5s;
}
.fa-long-arrow-alt-up {
display: none;
position: fixed;
bottom: 20px;
right: 20px;
z-index: 99;
border: none;
outline: none;
background: none;
color: black;
cursor: pointer;
padding: 15px;
font-size: 18px;
}
#myBtn:hover {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<title>Hector's Portfolio</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/javascript.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="layout-portfolio">
<nav id="navigation">
<a data-scroll class="main-nav" class="nav-hover" href="#home">Home</a>
<a data-scroll class="main-nav" class="nav-hover" href="#contact">Contact</a>
<a data-scroll class="main-nav" class="nav-hover" href="#about">About</a>
<a data-scroll class="main-nav" class="nav-hover" href="#projects">Projects</a>
</nav>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aperiam consectetur cupiditate deserunt dolore ducimus eius eos et ex explicabo fugit illo impedit inventore laudantium, maiores maxime minus quaerat, quasi rerum soluta tempore vel vitae? Ad, aliquid, consequatur deserunt distinctio expedita fuga labore modi perspiciatis quia ratione sequi sint soluta tempora, voluptates voluptatum. Aperiam consequuntur cumque delectus nulla odit placeat rem saepe sunt. Id labore magnam magni modi molestiae, neque possimus veniam? Blanditiis, commodi delectus dicta enim id incidunt modi nam quas saepe soluta. Aliquid, culpa, deserunt eveniet explicabo harum hic impedit maiores placeat qui quidem, quisquam reiciendis velit voluptatem? A atque consequatur, dolorum magni molestiae repudiandae saepe. Aliquid blanditiis debitis doloremque eum facere magni officiis similique soluta totam ullam! Aliquam amet aspernatur consectetur cumque ducimus et minima quis repellat repudiandae voluptate. Adipisci amet consectetur distinctio, error ex excepturi explicabo iure magnam neque obcaecati officiis quam quibusdam, vel, voluptas?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aperiam consectetur cupiditate deserunt dolore ducimus eius eos et ex explicabo fugit illo impedit inventore laudantium, maiores maxime minus quaerat, quasi rerum soluta tempore vel vitae? Ad, aliquid, consequatur deserunt distinctio expedita fuga labore modi perspiciatis quia ratione sequi sint soluta tempora, voluptates voluptatum. Aperiam consequuntur cumque delectus nulla odit placeat rem saepe sunt. Id labore magnam magni modi molestiae, neque possimus veniam? Blanditiis, commodi delectus dicta enim id incidunt modi nam quas saepe soluta. Aliquid, culpa, deserunt eveniet explicabo harum hic impedit maiores placeat qui quidem, quisquam reiciendis velit voluptatem? A atque consequatur, dolorum magni molestiae repudiandae saepe. Aliquid blanditiis debitis doloremque eum facere magni officiis similique soluta totam ullam! Aliquam amet aspernatur consectetur cumque ducimus et minima quis repellat repudiandae voluptate. Adipisci amet consectetur distinctio, error ex excepturi explicabo iure magnam neque obcaecati officiis quam quibusdam, vel, voluptas?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aperiam consectetur cupiditate deserunt dolore ducimus eius eos et ex explicabo fugit illo impedit inventore laudantium, maiores maxime minus quaerat, quasi rerum soluta tempore vel vitae? Ad, aliquid, consequatur deserunt distinctio expedita fuga labore modi perspiciatis quia ratione sequi sint soluta tempora, voluptates voluptatum. Aperiam consequuntur cumque delectus nulla odit placeat rem saepe sunt. Id labore magnam magni modi molestiae, neque possimus veniam? Blanditiis, commodi delectus dicta enim id incidunt modi nam quas saepe soluta. Aliquid, culpa, deserunt eveniet explicabo harum hic impedit maiores placeat qui quidem, quisquam reiciendis velit voluptatem? A atque consequatur, dolorum magni molestiae repudiandae saepe. Aliquid blanditiis debitis doloremque eum facere magni officiis similique soluta totam ullam! Aliquam amet aspernatur consectetur cumque ducimus et minima quis repellat repudiandae voluptate. Adipisci amet consectetur distinctio, error ex excepturi explicabo iure magnam neque obcaecati officiis quam quibusdam, vel, voluptas?</p>
<!-- Button to go to top -->
<button onclick="topFunction()" id="myBtn" class="fas fa-long-arrow-alt-up"></button>
</body>
</html>
I have a scrollable div for messages. I want opacity of 0.5 to the content at top 30% of scrollable div Like in image.
.
So while scrolling, whichever message comes on that div should have opacity 0.5. I have tried using an extra div background with linear gradient but the background color is clearly visible from my page's background color.Like this image So I just want to change the opacity of content but not the background of that region.
Thanks in advance.
.message-scroller {
height: 48vh;
overflow: hidden;
overflow-y:scroll;
position: relative;
width: 55%;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE 10+ */
display: flex;
//align-items: flex-end;
background-color: black
}
.sc-message{
padding: 0 10px 0 10px;
vertical-align: bottom;
width: 100%;
}
.single-message {
margin-bottom: 12px;
display: flex;
word-wrap: break-word;
flex-direction: row;
justify-content: space-between;
//overflow: hidden;
font-family: 'Barlow-SemiBold';
font-size: 22px;
color: #ffffff;
line-height: 24px;
.reserved{
margin-right: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.bot-img{
display: flex;
height: 30px;
width: 40px;
img{
height: 15px;
width: 20px;
}
}
.user-img{
display: flex;
margin-left: auto;
img{
height: 20px;
width: 15px;
}
// margin: auto;
//align-items: flex-end;
}
.message{
padding: 5px 10px 5px 10px;
color: #ffffff;
max-width: 85%;
}
.show-more{
color: #DF3535;
font-size: 24px;
}
.arabic-message{
text-align: right !important;
margin-left: auto;
margin-right: 2vw;
}
.show-more:hover{
cursor: pointer;
}
}
img{
height: 25px;
width : 25px;
}
<div class="message-scroller">
<div class="sc-message">
<div class="single-message">
<div class="bot-img">
<div class="reserved"></div>
</div>
<div class="message">
<div class="LinesEllipsis ">
<div>hello</div>
</div>
</div>
<div class="user-img"><img src="
https://drive.google.com/uc?export=view&id=1G037foK0nwRpvvClvl9_WHA5bI_65goV
"></div>
</div>
<div class="single-message">
<div class="bot-img"><img src="https://drive.google.com/uc?export=view&id=1pu1s3lGPPUmgiu6j0CSbkcZMVFA4c_YC
"></div>
<div class="message">
<div class="LinesEllipsis ">
<div>Hi, How can I help you today?</div>
</div>
</div>
<div class="user-img">
<div class="reserved"></div>
</div>
</div>
<div class="single-message">
<div class="bot-img">
<div class="reserved"></div>
</div>
<div class="message">
<div class="LinesEllipsis ">
<div>why?</div>
</div>
</div>
<div class="user-img"><img src="
https://drive.google.com/uc?export=view&id=1G037foK0nwRpvvClvl9_WHA5bI_65goV
"></div>
</div>
<div class="single-message">
<div class="bot-img"><img src="https://drive.google.com/uc?export=view&id=1pu1s3lGPPUmgiu6j0CSbkcZMVFA4c_YC
"></div>
<div class="message">
<div class="LinesEllipsis ">
<div>Sorry, I can't answer that at this moment.<br>Feel free to ask something else in the meantime.</div>
</div>
</div>
<div class="user-img">
<div class="reserved"></div>
</div>
</div>
<div class="single-message">
<div class="bot-img">
<div class="reserved"></div>
</div>
<div class="message">
<div class="LinesEllipsis ">
<div>ok</div>
</div>
</div>
<div class="user-img"><img src="
https://drive.google.com/uc?export=view&id=1G037foK0nwRpvvClvl9_WHA5bI_65goV
"></div>
</div>
<div class="single-message">
<div class="bot-img"><img src="https://drive.google.com/uc?export=view&id=1pu1s3lGPPUmgiu6j0CSbkcZMVFA4c_YC
"></div>
<div class="message">
<div class="LinesEllipsis ">
<div>Okay, I can help you with queries related to HIV/AIDs</div>
</div>
</div>
<div class="user-img">
<div class="reserved"></div>
</div>
</div>
</div>
</div>
Here is my solution.
.container {
position: relative;
height: 200px; no need: just to get scrollable content
}
.container:before {
content: '';
position: absolute;
width: 100%;
height: 30%;
background: linear-gradient(#00000080, #00000000);
}
.content {
padding-bottom: 100vh;// no need : to get scrolled content
<div class="container">
<p class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias amet animi culpa cupiditate, dicta dignissimos distinctio dolor doloribus dolorum enim ex explicabo, harum impedit inventore ipsa molestiae nesciunt nihil omnis pariatur perferendis perspiciatis porro, quae quaerat quisquam recusandae reprehenderit repudiandae sint sit tempore totam unde veritatis voluptas voluptates? Aliquid consequuntur cumque cupiditate deleniti doloremque error harum libero, nostrum obcaecati odio optio provident quas qui recusandae sapiente sequi voluptates? Culpa dolorem dolorum esse exercitationem illum maxime minus molestias nobis officia officiis porro quos, repellat soluta! A amet animi distinctio dolore enim error ex explicabo nostrum odio quia similique soluta, totam voluptas! At culpa error harum minus reiciendis ullam voluptatem. Corporis illo ipsa perspiciatis quasi ut. Asperiores autem delectus dignissimos dolorum eius explicabo, id, illo laudantium modi neque porro quaerat qui quibusdam quidem quisquam quos sequi similique suscipit tenetur, ullam velit veritatis vitae? Ab accusantium adipisci alias aperiam asperiores at atque blanditiis consequatur corporis debitis dignissimos distinctio dolore dolorum eaqu
</p>
</div>
I use a scroll slider with the mouse or by clicking on image. My problem is that the other links as in the footer or another no longer work. I added "onclick =" window.open (this.href); return false; "but now it's the slide that no longer works when the footer link was clicked.
Appreciate the help
$(function() {
//make functions first
function showSlide(n) {
// unbind event listener to prevent retriggering
$("body").unbind("mousewheel");
currSlide += n;
// make sure currslide does not go out of min or max boundaries
currSlide = currSlide <= 0 ? 0 : currSlide >= $slide.length-1 ? $slide.length-1 : currSlide;
// displacement is window width times current slide number
var displacment = window.innerWidth*currSlide;
// translate slides div across to appropriate slide
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
// give small delay before rebinding event to prevent retriggering
setTimeout(function() {
$("body").bind('mousewheel', mouseEvent);
}, 800);
// change active class on link
$('nav a.active').removeClass('active');
$($('a')[currSlide]).addClass('active');
}
function mouseEvent(e, delta) {
// On upwards scroll, show next slide (+1)
// otherwise on downwards scroll show prev slide (-1)
showSlide(delta >= 0 ? -1 : 1);
e.preventDefault();
}
$('nav a').click(function(e) {
// When link clicked, find slide it points to
var newslide = parseInt($(this).attr('href')[1]);
// find how far it is from current slide
var diff = newslide - currSlide - 1;
showSlide(diff); // show that slide
e.preventDefault();
});
$(window).resize(function(){
// Keep current slide to left of window on resize
var displacment = window.innerWidth*currSlide;
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
});
//declare vars then make things happen
var currSlide = 0; //Keeps track of slide
var $slide = $('.slide'); //all slides
// give active class to first link
$($('nav a')[0]).addClass('active');
//add event listener for mousescroll
$("body").bind('mousewheel', mouseEvent);
})
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
#-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #fff;
}
}
#keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #fff;
}
}
#-webkit-keyframes fillColour {
0% {
color: #fff;
}
50% {
color: #fff;
}
100% {
color: #333;
}
}
#keyframes fillColour {
0% {
color: #fff;
}
50% {
color: #fff;
}
100% {
color: #333;
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Open Sans", sans-serif;
}
html, body{
height:100%;
}
body {
font-size: 100%;
color:#555;
overflow:hidden;
}
[itemprop="logo"] {
float:right;
top:0;
padding: 20px;
}
[itemprop="description"] {
margin-top: 120px;
padding: 20px;
}
[itemprop="name"] {
text-align: right;
padding: 20px;
padding-bottom: 0;
}
[itemprop="faxNumber"] {
padding: 0 20px 0 0;
}
[itemprop="email"] {
padding: 0 20px 0 0;
}
[itemprop="address"] {
padding: 0 20px 0 0;
}
[itemprop="telephone"] {
padding: 0 20px 0 0;
color:#4a974d;
text-decoration: overline;
}
div{
text-align:right;
}
h1 {
font-size: 2.25em;
font-weight: 700;
text-align:center;
padding-top: 20px;
}
h2 {
font-size: 1.25em;
text-align:left;
color:#e7c6c6;
}
#footer {
bottom:0;
width:100%;
height:60px; /* Height of the footer */
margin-top: 20px;
}
#footer p {
color:#555;
text-align:center;
font-size: 12px;
}
#footer a{
color:#555;
text-decoration: none;
border-bottom: dotted 1px #555;
}
nav {
background: #fff;
position: absolute;
z-index: 100;
height: 100vh;
right: 0;
width: 10vw;
font-weight: 300;
font-size: 1rem;
width: 300px;
overflow:scroll;
}
nav ul {
position: absolute;
list-style-type: none;
height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
}
nav a, nav a:visited, nav a:active {
text-decoration: none;
color: #fff;
}
nav a {
/*position: absolute;*/
-webkit-transition: color 2s, background 1s;
transition: color 2s, background 1s;
padding: 3px;
z-index: 0;
}
nav a.active {
background: rgba(0, 0, 0, 0.9);
}
nav a::before {
content: "";
position: absolute;
height: 0%;
width: 0%;
bottom: 0;
left: 0;
opacity: 1;
background: #555;
z-index: -1;
}
nav img {
width:120px;
float: left;}
#nav-thumbnails {
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
padding: 1em 0.8em;
}
#nav-thumbnails h3{
font-size: 1.25em;
text-align:left;
color:#764a4a;
padding:8px;
}
/*nav a:hover {
-webkit-animation: fillColour 0.7s forwards ease-in-out;
animation: fillColour 0.7s forwards ease-in-out;
}
nav a:hover::before {
-webkit-animation: fill 0.7s forwards ease-in-out;
animation: fill 0.7s forwards ease-in-out;
opacity: 1;
}*/
#media only screen and (max-width: 460px) {
nav {
float: none;
margin-right:0;
width:auto;
border:0;
border-bottom:2px solid #000;
position: absolute;
overflow: scroll;
}
nav a {
padding: 3px;
}
nav a.active {
background: none;
}
nav img {
width: 100%;
}
.slides {
display:none;
}
#footer {
position: inherit;
}
[itemprop="logo"] {
float:right;
top:0;
padding: 20px;
width:120px;
}
}
.slides {
width: 600vw;
height: 100vh;
-webkit-transition: -webkit-transform 0.8s ease;
transition: -webkit-transform 0.8s ease;
transition: transform 0.8s ease;
transition: transform 0.8s ease, -webkit-transform 0.8s ease;
}
.slides .slide {
height: 100vh;
width: 100vw;
background: pink;
float: left;
text-align: center;
background-size: cover;
}
.slides .slide .content {
max-width: 600px;
padding: 20px;
background: rgba(24, 20, 20, 0.35);
/* margin: 35vh 0 0 15vw; */
border-radius: 5px;
position: absolute;
bottom: 0;
}
.slides .slide .content p {
padding: 10px 0;
border-bottom: 1px solid #f2e9e9;
width: 100%;
}
.slides .slide:nth-child(1) {
background-image: url(../img/1.jpg);
}
.slides .slide:nth-child(2) {
background-image: url(../img/2.jpg);
}
.slides .slide:nth-child(3) {
background-image: url(../img/3.jpg);
}
.slides .slide:nth-child(4) {
background-image: url(../img/4.jpg);
}
.slides .slide:nth-child(5) {
background-image: url(../img/5.jpg);
}
.slides .slide:nth-child(6) {
background-image: url(../img/6.jpg);
}
.slides .slide:nth-child(7) {
background-image: url(../img/7.jpg);
}
.slides .slide:nth-child(8) {
background-image: url(../img/8.jpg);
}
.slides .slide:nth-child(9) {
background-image: url(../img/9.jpg);
}
.slides .slide:nth-child(10) {
background-image: url(../img/10.jpg);
}
.slides .slide img {
width: 100%;
}
.slides .slide p {
color:#fff;
text-align:left;
}
#media only screen and (max-width: 900px) {
.slides .slide .content {
width: 300px;
}
.slides .slide .content p {
padding: 0;
border-bottom: 0;
}
}
<!DOCTYPE html>
<html lang="zxx">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet prefetch' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<main>
<nav>
<header>
<h1>Pepinière Paris</h1>
<!--snippet pour le seo-->
<div itemscope="" itemtype="http://schema.org/ProfessionalService">
<div itemprop="name">Brewer Digital Marketing</div>
<img itemprop="logo" src="http://img4.hostingpics.net/pics/379486logo.png" alt="logo">
<div itemprop="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquam eget eros vitae facilisis. Donec mollis turpis eu lorem imperdiet, vel pellentesque nunc tempor.</div>
<div>Phone:
<span itemprop="telephone">303-406-1053</span>
</div>
<div>Fax:
<span itemprop="faxNumber">555-555-5555</span>
</div>
<div>Email:
<span itemprop="email">brad#mail.com</span>
</div>
<div itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">1889 Rutherford Ave</span>
P.O. Box: <span itemprop="postOfficeBoxNumber">5555</span>
<span itemprop="addressLocality">Louisville</span>
<span itemprop="postalCode">40205</span>
<span itemprop="addressCountry">USA</span>
</div>
</div>
</header>
<!--section de navigation-->
<section id="nav-thumbnails">
<h3>La pépinière</h3>
<img src="img/1.jpg" alt="image1">
<img src="img/2.jpg" alt="image2">
<img src="img/3.jpg" alt="image3">
<img src="img/4.jpg" alt="image4">
<img src="img/5.jpg" alt="image5">
<img src="img/6.jpg" alt="image6">
</section>
<!--footer-->
<div id="footer"><p>Crédit : pixabay.com</p></div>
</nav>
</main>
<div class="slides">
<div id="1" class="slide">
<div class="content">
<h2>Slide 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="2" class="slide">
<div class="content">
<h2>Slide 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="3" class="slide">
<div class="content">
<h2>Slide 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="4" class="slide">
<div class="content">
<h2>Slide 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="5" class="slide">
<div class="content">
<h2>Slide 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="6" class="slide">
<div class="content">
<h2>Slide 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
Jquery is correct, just you need take footer div outside the <nav> tag.
<nav>
<header>
<h1>Pepinière Paris</h1>
<!--snippet pour le seo-->
<div itemscope="" itemtype="http://schema.org/ProfessionalService">
<div itemprop="name">Brewer Digital Marketing</div>
<img itemprop="logo" src="http://img4.hostingpics.net/pics/379486logo.png" alt="logo">
<div itemprop="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquam eget eros vitae facilisis. Donec mollis turpis eu lorem imperdiet, vel pellentesque nunc tempor.</div>
<div>Phone:
<span itemprop="telephone">303-406-1053</span>
</div>
<div>Fax:
<span itemprop="faxNumber">555-555-5555</span>
</div>
<div>Email:
<span itemprop="email">brad#mail.com</span>
</div>
<div itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">1889 Rutherford Ave</span>
P.O. Box: <span itemprop="postOfficeBoxNumber">5555</span>
<span itemprop="addressLocality">Louisville</span>
<span itemprop="postalCode">40205</span>
<span itemprop="addressCountry">USA</span>
</div>
</div>
</header>
<!--section de navigation-->
<section id="nav-thumbnails">
<h3>La pépinière</h3>
<img src="img/1.jpg" alt="image1">
<img src="img/2.jpg" alt="image2">
<img src="img/3.jpg" alt="image3">
<img src="img/4.jpg" alt="image4">
<img src="img/5.jpg" alt="image5">
<img src="img/6.jpg" alt="image6">
</section>
<!--footer-->
</nav>
<div id="footer"><p>Credit : pixabay.com</p></div>
</main>
<div class="slides">
<div id="1" class="slide">
<div class="content">
<h2>Slide 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="2" class="slide">
<div class="content">
<h2>Slide 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="3" class="slide">
<div class="content">
<h2>Slide 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="4" class="slide">
<div class="content">
<h2>Slide 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="5" class="slide">
<div class="content">
<h2>Slide 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="6" class="slide">
<div class="content">
<h2>Slide 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
</div>
Add onkeypress="window.open(this.href); return false;" to your code
pixabay.com
Remove below code
$('nav a').click(function(e) {
// When link clicked, find slide it points to
var newslide = parseInt($(this).attr('href')[1]);
// find how far it is from current slide
var diff = newslide - currSlide - 1;
showSlide(diff); // show that slide
e.preventDefault();
});
add this code to your js file.
$('#nav-thumbnails a').click(function(e) {
var newslide = parseInt($(this).attr('href')[1]);
var diff = newslide - currSlide - 1; showSlide(diff);
e.preventDefault();
});
$(function() {
//make functions first
function showSlide(n) {
// unbind event listener to prevent retriggering
$("body").unbind("mousewheel");
currSlide += n;
// make sure currslide does not go out of min or max boundaries
currSlide = currSlide <= 0 ? 0 : currSlide >= $slide.length-1 ? $slide.length-1 : currSlide;
// displacement is window width times current slide number
var displacment = window.innerWidth*currSlide;
// translate slides div across to appropriate slide
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
// give small delay before rebinding event to prevent retriggering
setTimeout(function() {
$("body").bind('mousewheel', mouseEvent);
}, 800);
// change active class on link
$('nav a.active').removeClass('active');
$($('a')[currSlide]).addClass('active');
}
function mouseEvent(e, delta) {
// On upwards scroll, show next slide (+1)
// otherwise on downwards scroll show prev slide (-1)
showSlide(delta >= 0 ? -1 : 1);
e.preventDefault();
}
$('#nav-thumbnails a').click(function(e) { var newslide = parseInt($(this).attr('href')[1]); var diff = newslide - currSlide - 1; showSlide(diff); e.preventDefault(); });
$(window).resize(function(){
// Keep current slide to left of window on resize
var displacment = window.innerWidth*currSlide;
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
});
//declare vars then make things happen
var currSlide = 0; //Keeps track of slide
var $slide = $('.slide'); //all slides
// give active class to first link
$($('nav a')[0]).addClass('active');
//add event listener for mousescroll
$("body").bind('mousewheel', mouseEvent);
})
#import url(http://fonts.googleapis.com/css?family=Open+Sans);
#-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #fff;
}
}
#keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #fff;
}
}
#-webkit-keyframes fillColour {
0% {
color: #fff;
}
50% {
color: #fff;
}
100% {
color: #333;
}
}
#keyframes fillColour {
0% {
color: #fff;
}
50% {
color: #fff;
}
100% {
color: #333;
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Open Sans", sans-serif;
}
html, body{
height:100%;
}
body {
font-size: 100%;
color:#555;
overflow:hidden;
}
[itemprop="logo"] {
float:right;
top:0;
padding: 20px;
}
[itemprop="description"] {
margin-top: 120px;
padding: 20px;
}
[itemprop="name"] {
text-align: right;
padding: 20px;
padding-bottom: 0;
}
[itemprop="faxNumber"] {
padding: 0 20px 0 0;
}
[itemprop="email"] {
padding: 0 20px 0 0;
}
[itemprop="address"] {
padding: 0 20px 0 0;
}
[itemprop="telephone"] {
padding: 0 20px 0 0;
color:#4a974d;
text-decoration: overline;
}
div{
text-align:right;
}
h1 {
font-size: 2.25em;
font-weight: 700;
text-align:center;
padding-top: 20px;
}
h2 {
font-size: 1.25em;
text-align:left;
color:#e7c6c6;
}
#footer {
bottom:0;
width:100%;
height:60px; /* Height of the footer */
margin-top: 20px;
}
#footer p {
color:#555;
text-align:center;
font-size: 12px;
}
#footer a{
color:#555;
text-decoration: none;
border-bottom: dotted 1px #555;
}
nav {
background: #fff;
position: absolute;
z-index: 100;
height: 100vh;
right: 0;
width: 10vw;
font-weight: 300;
font-size: 1rem;
width: 300px;
overflow:scroll;
}
nav ul {
position: absolute;
list-style-type: none;
height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
}
nav a, nav a:visited, nav a:active {
text-decoration: none;
color: #fff;
}
nav a {
/*position: absolute;*/
-webkit-transition: color 2s, background 1s;
transition: color 2s, background 1s;
padding: 3px;
z-index: 0;
}
nav a.active {
background: rgba(0, 0, 0, 0.9);
}
nav a::before {
content: "";
position: absolute;
height: 0%;
width: 0%;
bottom: 0;
left: 0;
opacity: 1;
background: #555;
z-index: -1;
}
nav img {
width:120px;
float: left;}
#nav-thumbnails {
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
padding: 1em 0.8em;
}
#nav-thumbnails h3{
font-size: 1.25em;
text-align:left;
color:#764a4a;
padding:8px;
}
/*nav a:hover {
-webkit-animation: fillColour 0.7s forwards ease-in-out;
animation: fillColour 0.7s forwards ease-in-out;
}
nav a:hover::before {
-webkit-animation: fill 0.7s forwards ease-in-out;
animation: fill 0.7s forwards ease-in-out;
opacity: 1;
}*/
#media only screen and (max-width: 460px) {
nav {
float: none;
margin-right:0;
width:auto;
border:0;
border-bottom:2px solid #000;
position: absolute;
overflow: scroll;
}
nav a {
padding: 3px;
}
nav a.active {
background: none;
}
nav img {
width: 100%;
}
.slides {
display:none;
}
#footer {
position: inherit;
}
[itemprop="logo"] {
float:right;
top:0;
padding: 20px;
width:120px;
}
}
.slides {
width: 600vw;
height: 100vh;
-webkit-transition: -webkit-transform 0.8s ease;
transition: -webkit-transform 0.8s ease;
transition: transform 0.8s ease;
transition: transform 0.8s ease, -webkit-transform 0.8s ease;
}
.slides .slide {
height: 100vh;
width: 100vw;
background: pink;
float: left;
text-align: center;
background-size: cover;
}
.slides .slide .content {
max-width: 600px;
padding: 20px;
background: rgba(24, 20, 20, 0.35);
/* margin: 35vh 0 0 15vw; */
border-radius: 5px;
position: absolute;
bottom: 0;
}
.slides .slide .content p {
padding: 10px 0;
border-bottom: 1px solid #f2e9e9;
width: 100%;
}
.slides .slide:nth-child(1) {
background-image: url(../img/1.jpg);
}
.slides .slide:nth-child(2) {
background-image: url(../img/2.jpg);
}
.slides .slide:nth-child(3) {
background-image: url(../img/3.jpg);
}
.slides .slide:nth-child(4) {
background-image: url(../img/4.jpg);
}
.slides .slide:nth-child(5) {
background-image: url(../img/5.jpg);
}
.slides .slide:nth-child(6) {
background-image: url(../img/6.jpg);
}
.slides .slide:nth-child(7) {
background-image: url(../img/7.jpg);
}
.slides .slide:nth-child(8) {
background-image: url(../img/8.jpg);
}
.slides .slide:nth-child(9) {
background-image: url(../img/9.jpg);
}
.slides .slide:nth-child(10) {
background-image: url(../img/10.jpg);
}
.slides .slide img {
width: 100%;
}
.slides .slide p {
color:#fff;
text-align:left;
}
#media only screen and (max-width: 900px) {
.slides .slide .content {
width: 300px;
}
.slides .slide .content p {
padding: 0;
border-bottom: 0;
}
}
<!DOCTYPE html>
<html lang="zxx">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet prefetch' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<main>
<nav>
<header>
<h1>Pepinière Paris</h1>
<!--snippet pour le seo-->
<div itemscope="" itemtype="http://schema.org/ProfessionalService">
<div itemprop="name">Brewer Digital Marketing</div>
<img itemprop="logo" src="http://img4.hostingpics.net/pics/379486logo.png" alt="logo">
<div itemprop="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquam eget eros vitae facilisis. Donec mollis turpis eu lorem imperdiet, vel pellentesque nunc tempor.</div>
<div>Phone:
<span itemprop="telephone">303-406-1053</span>
</div>
<div>Fax:
<span itemprop="faxNumber">555-555-5555</span>
</div>
<div>Email:
<span itemprop="email">brad#mail.com</span>
</div>
<div itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">1889 Rutherford Ave</span>
P.O. Box: <span itemprop="postOfficeBoxNumber">5555</span>
<span itemprop="addressLocality">Louisville</span>
<span itemprop="postalCode">40205</span>
<span itemprop="addressCountry">USA</span>
</div>
</div>
</header>
<!--section de navigation-->
<section id="nav-thumbnails">
<h3>La pépinière</h3>
<img src="img/1.jpg" alt="image1">
<img src="img/2.jpg" alt="image2">
<img src="img/3.jpg" alt="image3">
<img src="img/4.jpg" alt="image4">
<img src="img/5.jpg" alt="image5">
<img src="img/6.jpg" alt="image6">
</section>
<!--footer-->
<div id="footer"><p>Crédit : pixabay.com</p></div>
</nav>
</main>
<div class="slides">
<div id="1" class="slide">
<div class="content">
< h2>Slide 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="2" class="slide">
<div class="content">
<h2>Slide 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="3" class="slide">
<div class="content">
<h2>Slide 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="4" class="slide">
<div class="content">
<h2>Slide 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="5" class="slide">
<div class="content">
<h2>Slide 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
<div id="6" class="slide">
<div class="content">
<h2>Slide 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam, odit nihil tempora tenetur! Fugit reprehenderit saepe impedit at, expedita nemo nulla hic quia placeat ipsum sint, quis unde fugiat tenetur nobis illum. Nemo laboriosam laudantium aliquam illum fugiat incidunt nostrum, corrupti minus optio. Suscipit obcaecati harum voluptates est quod quasi?</p>
</div>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
I have made the changes in jquery .You can take below code.
$(function() {
//make functions first
function showSlide(n) {
// unbind event listener to prevent retriggering
$("body").unbind("mousewheel");
currSlide += n;
// make sure currslide does not go out of min or max boundaries
currSlide = currSlide <= 0 ? 0 : currSlide >= $slide.length-1 ? $slide.length-1 : currSlide;
// displacement is window width times current slide number
var displacment = window.innerWidth*currSlide;
// translate slides div across to appropriate slide
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
// give small delay before rebinding event to prevent retriggering
setTimeout(function() {
$("body").bind('mousewheel', mouseEvent);
}, 800);
// change active class on link
$('nav #nav-thumbnails a.active').removeClass('active');
$($('a')[currSlide]).addClass('active');
}
function mouseEvent(e, delta) {
// On upwards scroll, show next slide (+1)
// otherwise on downwards scroll show prev slide (-1)
showSlide(delta >= 0 ? -1 : 1);
e.preventDefault();
}
$('nav #nav-thumbnails a').click(function(e) {
// When link clicked, find slide it points to
var newslide = parseInt($(this).attr('href')[1]);
// find how far it is from current slide
var diff = newslide - currSlide - 1;
showSlide(diff); // show that slide
e.preventDefault();
});
$(window).resize(function(){
// Keep current slide to left of window on resize
var displacment = window.innerWidth*currSlide;
$('.slides').css('transform', 'translateX(-'+displacment+'px)');
});
//declare vars then make things happen
var currSlide = 0; //Keeps track of slide
var $slide = $('.slide'); //all slides
// give active class to first link
$($('nav #nav-thumbnails a')[0]).addClass('active');
//add event listener for mousescroll
$("body").bind('mousewheel', mouseEvent);
})
Practically I have a vertical tabs menu and what I am trying to achieve is to have the menu wrapper height dynamically set depending on the content or the tabs height (the one that is bigger wins)
Here is a jsfiddle of what I have made so far : http://jsfiddle.net/f9zt9xqr/2/
HTML:
<div id="page-wrap">
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Tab One</label>
<div class="content">
<p>Stuff for Tab One</p>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab Two</label>
<div class="content">
<p>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</p>
<p>Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla?</p>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">Tab Three</label>
<div class="content">
<p>Stuff for Tab Three</p>
</div>
</div>
</div>
</div>
CSS:
* {
gmargin: 0;
spadding: 0;
}
body {
background: #f9f9fc;
}
#tab-1{
position: absolute;
top: -200px;
left: -200px;
}
#tab-3{
position: absolute;
top: -200px;
left: -200px;
}
#tab-2{
position: absolute;
top: -200px;
left: -200px;
}
#page-wrap{
position: relative;
background:#123456;
}
.tabs {
position: relative;
hmin-height: 200px;
/* This part sucks */
clear: both;
smargin: 25px 0;
}
.tab {
rfloat: left;
sposition:absolute;
height: auto;
}
.tab label {
background: #f5f5f9;
padding: 10px;
border: 1px solid #ccc;
margin-left: -1px;
dposition: relative;
left: 1px;
width: 70px;
display: block;
}
.tab[type=radio] {
display: none;
}
.content {
display:none;
position: absolute;
top: 0px;
left: 92px;
background: white;
right: 0;
zbottom: 0;
padding: 20px;
border: 1px solid #ccc;
}
[type=radio]:checked ~ label {
background: white;
sborder-bottom: 1px solid white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
8overflow:auto;
display:inline;
z-index: 1;
}
on the second option you can clearly notice that the page-wrap doesn't extend to the content size
I was thinking that this is because content is an inner element of tab and therefore should be modified there but it didn't work either.
Any suggestions how to achieve that and maybe don't mind explaining what I was doing wrong ?
.tabs { display:table; }
label {display:table-cell;}
.content {display-table:cell;}
remove position absolute as it won't help you in this situation. See how it goes
PS: remove the display:inline from [type="radio"]:checked ~ label ~ .content
I updated the css to take out some of the absolute positioning and made the content have a min-height of 100%, this also required taking out the vertical padding of the content area.
http://jsfiddle.net/f9zt9xqr/4/
.content {
display:none;
position: absolute;
top: 0;
left: 92px;
background: white;
right: 0;
padding: 0 20px;
border: 1px solid #ccc;
min-height: 100%;
}