Class active not shown - javascript
I'm making a slideshow as explained in the W3School example below:
https://www.w3schools.com/howto/howto_js_slideshow.asp
I have the following issue: the active class is not shown when refreshing the page.
Here is the link to the problem.
https://github.com/FrancoisXavierPelletier/Intermarium24.com/issues/1
Best regards.
I have tried to modify the first margins and width to match the needs, but the second and third images do not show this margin.
Expected change: The code should add an active class to be displayed and show it by default. This can be done in Javascript.
Result: When refreshing the page, instead of having the slideshow not visible, the first slide should be active.
Here is the code in Javascript I use:
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
*{
margin: 0;
padding; 0;
background: darkslategrey;
}
body{
font-family: arial, sans-serif;
}
h1{
font-family: 'Crete Round', serif;
font-size: 45px;
color: whitesmoke;
}
.wrapper{
width: 940px;
margin: 0 auto;
padding: 0 0;
}
.orange{
color: orange;
}
header ul{
list-style: none;
}
header a{
text-decoration: none;
color: whitesmoke;
font-weight: bold;
margin-right: 20px;
}
header{
height:100px;
}
header h1{
float: left;
margin-top: 25px;
}
header nav{
float: right;
margin-top: 50px;
}
header nav li
{
display: inline-block;
}
header nav li a {
text-transform: uppercase;
}
.clear{
clear: both;
}
/* Slideshow */
.slideshow-container {
max-width: 940px;
position: relative;
margin: auto;
background: red;
}
.mySlides {
display: none;
height: 300px;
width: 97.5%;
border: 1px solid white;
border-radius: 10px;
}
#slide1{
background: url('images/img1.jpg') center;
}
#slide2{
background: url('images/img1.jpg') center;
}
#slide3{
background: url('images/img1.jpg') center;
}
.prev, .next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.prev {
left: 150px;
border-radius: 3px 0 0 3px;
}
.next {
right: 150px;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
border-radius: 3px 0 0 3px;
}
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
margin-top: 237px;
position: relative;
width: 97.4%;
text-align: justify;
background: black;
opacity: 0.8;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: relative;
top: 0;
background: transparent;
}
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* Category */
.category{
height: 200px;
width: 172px;
background: red;
float: left;
margin: 20px 5px;
border: 1px solid white;
border-radius: 5px;
}
#military{
background: url('images/military.jpg') center;
}
#economy{
background: url('images/economy.jpg') center;
}
#society{
background: url('images/social.jpg') center;
}
#culture{
background: url('images/culture.jpg') center;
}
#tech{
background: url('images/tech.jpg') center;
}
h2{
color: white;
font-size: 20px;
text-align: center;
margin-top: 150px;
padding: 5px;
text-transform: uppercase;
font-family: 'Crete Round', serif;
background: black;
opacity: 0.8;
}
/* footer */
footer{
height: 250px;
background-color: white;
}
.footer-div{
background: white;
margin: 20px;
float: left;
width: 20%;
height: 200px;
}
h3{
background: transparent;
color: black;
text-transform: uppercase;
font-weight: bold;
padding: 10px;
margin-top: 10px;
}
footer ul{
list-style: none;
background: white;
}
footer li{
padding: 5px;
background: white;
}
footer a{
background: white;
}
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title> Intermarium24.pl </title>
<link href="http://fonts.googleapis.com/css?family=Crete+Round" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<script src="myscript.js"></script>
</head>
<header>
<div class="wrapper">
<h1>Intermarium<span class="orange">24</span>.com</h1>
<nav>
<ul>
<li>Home </li>
<li>Discover </li>
<li>Register </li>
<li>Login </li>
<li>Contact </li>
</ul>
</nav>
</div>
</header>
<section id="slideshow">
<div class="wrapper">
<div id="slideshow-container">
<div class="mySlides fade" id="slide1">
<div class="numbertext">1 / 3</div>
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade" id="slide2">
<div class="numbertext">2 / 3</div>
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade" id="slide3">
<div class="numbertext">3 / 3</div>
<div class="text">Caption Three</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</section>
<div class="clear"></div>
<section id="Main-articles">
<div class="wrapper">
<div class="category" id="military">
<h2>Military</h2>
</div>
<div class="category" id="economy">
<h2>Economy</h2>
</div>
<div class="category" id="society">
<h2>Society</h2>
</div>
<div class="category" id="culture">
<h2>Culture</h2>
</div>
<div class="category" id="tech">
<h2>Tech</h2>
</div>
</div>
<div class="clear"></div>
</section>
<footer>
<div class="wrapper">
<div class="footer-div">
<h3> Main menu</h3>
<ul>
<li><a>Home </a></li>
<li><a>Discover </a></li>
<li><a>Register </a></li>
<li><a>Login </a></li>
<li><a>Contact</a></li>
</ul>
</div>
<div class="footer-div" id="footer-category">
<h3> Categories</h3>
<ul>
<li><a>Military </a></li>
<li><a>Economy </a></li>
<li><a>Social </a></li>
<li><a>Cultural </a></li>
<li><a>Tech</a></li>
</ul>
</div>
<div class="footer-div" id="footer-legal">
<h3> Categories</h3>
<ul>
<li><a>Terms of Sales </a></li>
<li><a>Terms of Use </a></li>
<li><a>Privacy Policy </a></li>
<li><a>Legal Contact </a></li>
</ul>
</div>
<div class="footer-div" id="footer-socmed">
<h3> Social medias</h3>
<ul>
<li><a>Facebook </a></li>
<li><a>Twitter </a></li>
<li><a>Contact </a></li>
</ul>
</div>
</div>
</footer>
</html>
Related
How do I make slideshow appear by default?
I am unable to make a slideshow appear by default on my website. This is what I'm trying to get : https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow (but with 2 photos instead of 3) However, this is what I am getting: image The photos only appear when i click the left or right arrows var slideIndex = 1; showSlides(slideIndex); function plusSlides(n) { showSlides(slideIndex += n); } function currentSlide(n) { showSlides(slideIndex = n); } function showSlides(n) { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); if (n > slides.length) {slideIndex = 1} if (n < 1) {slideIndex = slides.length} for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; } html{ font-family: Arial, Helvetica, sans-serif; } h1{ text-align: center; } .topnav a { display: inline-block; color: black; background-color: rgb(233, 233, 233); text-align: center; padding: 5px; text-decoration: none; font-size: 17px; flex: 1; border: 3px solid black; } ul{ display: flex; justify-content: center; border-left: 2px solid black; border-right: 2px solid black; border-top: 5px solid black; border-bottom: 5px solid black; padding: 0; background-color: black; } body{ height: 100vh; background-image: linear-gradient( rgb(35, 166, 252), white); } * {box-sizing: border-box} body {font-family: Arial, Helvetica, sans-serif; margin:0} .mySlides {display: none} img {vertical-align: middle;} /* Slideshow container */ .slideshow-container { max-width: 1000px; position: relative; margin: auto; } /* Next & previous buttons */ .prev, .next { cursor: pointer; position: absolute; top: 50%; width: auto; padding: 16px; margin-top: -22px; color: white; font-weight: bold; font-size: 18px; transition: 0.6s ease; border-radius: 0 3px 3px 0; user-select: none; } /* Position the "next button" to the right */ .next { right: 0; border-radius: 3px 0 0 3px; } /* On hover, add a black background color with a little bit see-through */ .prev:hover, .next:hover { background-color: rgba(0,0,0,0.8); } /* Caption text */ .text { color: #f2f2f2; font-size: 15px; padding: 8px 12px; position: absolute; bottom: 8px; width: 100%; text-align: center; } /* Number text (1/3 etc) */ .numbertext { color: #f2f2f2; font-size: 12px; padding: 8px 12px; position: absolute; top: 0; } /* The dots/bullets/indicators */ .dot { cursor: pointer; height: 15px; width: 15px; margin: 0 2px; background-color: #bbb; border-radius: 50%; display: inline-block; transition: background-color 0.6s ease; } .active, .dot:hover { background-color: #717171; } /* Fading animation */ .fade { -webkit-animation-name: fade; -webkit-animation-duration: 1.5s; animation-name: fade; animation-duration: 1.5s; } #-webkit-keyframes fade { from {opacity: .4} to {opacity: 1} } #keyframes fade { from {opacity: .4} to {opacity: 1} } <!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"> <title>Document</title> <link href="mypast.css" rel="stylesheet"> <script src="mypast.js"></script> <h1>MY PAST</h1> <div class="topnav"> <nav> <ul> About Me My Past My Present My Future Feedback </ul> </nav> </div> </head> <body> <div class="slideshow-container"> <div class="mySlides fade"> <div class="numbertext">1 / 2</div> <img src="friends.jpg" style="width:100%"> <div class="text">Caption one</div> </div> <div class="mySlides fade"> <div class="numbertext">2 / 2</div> <img src="badmintonteam.jpg" style="width:100%"> <div class="text">Caption two</div> </div> <a class="prev" onclick="plusSlides(-1)">❮</a> <a class="next" onclick="plusSlides(1)">❯</a> </div> <br> <div style="text-align:center"> <span class="dot" onclick="currentSlide(1)"></span> <span class="dot" onclick="currentSlide(2)"></span> </div> </body> </html>
setInterval(function(){ document.getElementById('yourNextSliderbuttonID').click(); },1000); // the button will be clicked every 1000milisec/1 secenter code here
Image Modal or Expand when click in html and css
So i am trying to put a code for modal or in order to expand my images. I already checked every sector or every codes and still didn't find why it's not working. I don't want nothing to change in it except the modal, it my get mess up if i change things. I got the codes from a website. In the site their result are working but when i put the codes in the notepad nothing happened. It will be really helpful if you can find what is wrong with it. Thank you in advance for those who will help me. body { display: grid; grid-template-columns: 100%; grid-template-rows: 8vw 130vw 7vw; grid-gap: 0em; margin: 0; padding: 0; background-color: #ffffff; width: 100%; } header, footer { grid-column: 1 / span 2; } main { grid-column: 1 / span 2; } body { margin: 0 auto; max-width: 89em; margin-left: 0; margin-right:0; padding: 0em 0; } header, main, aside, footer { display: flex; } footer { background: #eaeaea; } .main1 { margin-top: 450px; margin-left: 0; } #body_1 h2 { margin-left: 50px; font-size: 30px; color: black; margin-top: 95px; margin-bottom:3px; font-family: courier new; float: left; } #body_1 h6 { margin-left: 10px; color: blue; margin-top: 220px; margin-bottom:3px; font-family: courier new; float: left; } #body_1 h4 { margin-left: 230px; font-size: 30px; color: black; margin-top: 260px; margin-bottom:3px; position: left; float: left; } .text4 { position: absolute; float: left; top: 870px; } .background_wrap { position: absolute; background-color: rgba(19, 13, 6,0.5); z-index: -1000; width: 100%; height: 100% ; overflow:hidden; background: url("Pics&Video/laoang6.jpg") no-repeat center; background-size: cover; } .background_wrap::before{ background-color: rgba(0, 0, 0, 0.37); content: ''; display: block; height: 100%; position: absolute; width: 100%; } .content { position: absolute; width: 100%; min-height: 20%; z-index: 1000; } .sub-content { position: fixed; width: 1000px; height: 120px; margin: 0 auto; transition: 0.5s; } .sub-content.active { background-color: rgba(0, 26, 26,0.7); width: 100% } .sub-content.active ul li a { background-color: rgba(0, 26, 26,0.7); } #list { margin-right: 5px; position:fixed; margin-left: 780px; margin-top: 20px; } ul { margin-top:1px; padding: 0px; list-style: none; color: white; margin-right: 0px; font-family: calibri; font-weight: bold; } ul li { float: right; width: 130px; font-family: courier new; border-bottom: 1px solid #ffffff; border-right: 1px solid #ffffff ; border-left: 1px solid #ffffff ; border-top: 1px solid #ffffff ; line-height: 25px; text-align: center; font-size: 13px; font-weight: bolder; margin-top: 35px; margin-right: 3px; } ul li a { color: white; display: block; margin-top: 2px; font-weight: bolder; text-decoration: none; } ul li a:hover { background-color: green; font-weight:bolder; cursor: pointer; color: white } ul li ul li { display: none; font-weight: bolder; } ul li:hover ul li { display:block; cursor: pointer; color: white; margin-top:1px; margin-right: 0px; position: center; background-size: cover; font-weight: bolder; } h1 { font-family: comic sans ms, sans-serif; text-align: center; font-size: 60px; text-transform: uppercase; font-weight: bolder; color: white; margin-bottom: 6px; } h2 { font-family: comic sans ms, sans-serif; text-align: center; font-size: 30px; text-transform: uppercase; font-weight: 300; color: white; padding-top: 14%; } .wrapper { position: center; width: 750px; height: 100px; margin-left:auto; margin-right:auto; margin-top: 150px; font-size: 17px; } .image_wrap { margin-top:20px; height: 70px; margin-left:55px; } .fl_image { float: left; margin-right:5px; margin-bottom: 10px; } .content h6 { font-family: courier new; font-size: 13px; text-transform: uppercase; font-weight: 300; color: green; margin-bottom: 10px; margin-left: 25px; margin-top: 100px; } .content p { font-family: courier new; text-align: center; font-size: 20px; letter-spacing: 3px; color: #ffffff; } div.gallery { margin: 10px; border: 0px solid #ccc; float: left; width: 250px; height:250px; } div.gallery:hover { border: 1px solid #777; } div.gallery img { width: 100%; height: 100%; } .gallery1 { float: left; position: absolute; margin-top: 320px; margin-left: 10px; } div.gallery { margin: 10px; border: 0px solid #ccc; float: left; width: 300px; height:250px; } div.gallery:hover { border: 1px solid #777; } div.gallery img { width: 100%; height: 100%; } .gallery2 { float: left; position: absolute; margin-top: 840px; margin-left: 10px; } .text4 { margin-left: 360px; font-size: 30px; color: black; margin-top: 220px; margin-bottom:3px; position: left; float: left; } #myImg { border-radius: 5px; cursor: pointer; transition: 0.3s; } #myImg:hover {opacity: 0.7;} /* The Modal (background) */ .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 10000 ; /* Sit on top */ padding-top: 100px; /* Location of the box */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.9); /* Black w/ opacity */ } /* Modal Content (Image) */ .modal-content { margin: auto; display: block; width: 80%; max-width: 600px; max-height: 450px; } /* Caption of Modal Image (Image Text) - Same Width as the Image */ #caption { margin: auto; display: block; width: 80%; max-width: 700px; text-align: center; color: #ccc; padding: 10px 0; height: 150px; } /* Add Animation - Zoom in the Modal */ .modal-content, #caption { animation-name: zoom; animation-duration: 0.6s; } #keyframes zoom { from {transform:scale(0)} to {transform:scale(1)} } /* The Close Button */ .close { position: absolute; top: 15px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; transition: 0.3s; } .close:hover, .close:focus { color: #bbb; text-decoration: none; cursor: pointer; } /* 100% Image Width on Smaller Screens */ #media only screen and (max-width: 700px){ .modal-content { width: 100%; } } .transparent_btn { font-size: 10px; line-height: 50px; color: #EC7063 ; background-color: transparent; border: 1px solid #D98880; padding: 1px 20px; border-radius: 10px; text-decoration: none; cursor: pointer; transition: background-color ease 300ms; font-weight: 200; font-size: 16px; margin-top: 620px; float: left; } .transparent_btn:hover { color: #fff; background-color: rgba(245, 183, 177,0.8); } .btn { position: absolute; z-index: 1; margin-left: 640px; } .btn2 { position: absolute; margin-top: 530px; margin-left: 640px; } <!Doctype html> <html> <head> <title> Hotels </title> <link style="text/css" href="Hotel.css" rel="stylesheet" > </link> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(window).on('scroll', function(){ if($(window).scrollTop()){ $(".sub-content").addClass('active'); }else{ $(".sub-content").removeClass('active'); } }) }); </script> <script> $(document).ready(function(){ // Get the modal var modal = document.getElementById('myModal'); // Get the image and insert it inside the modal - use its "alt" text as a caption var img = document.getElementById('myImg'); var modalImg = document.getElementById("img04"); var captionText = document.getElementById("caption"); img.onclick = function(){ modal.style.display = "block"; modalImg.src = this.src; captionText.innerHTML = this.alt; } // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } }); </script> </head> <body> <header> <div class="background_wrap"> </div> <div class="content"> <div class="sub-content"> <img class="image_wrap fl_image" src="Pics&Video\picture.png" height="100px" margin-left="5px" alt="Image One"/> <div id="list" > <ul> <li><a> <i class="fas fa-file-signature"></i> Contact</a></li> <li> <i class="fas fa-user"></i> About</li> <li> History </i></li> <li><a> Activities <i class="fas fa-caret-down"></i></a> <ul> <li> Hotels</li> <li> Festival</li> </ul> </li> </ul> </div> <h6>Calbayog Tourism</h6> </div> </div> <div class="wrapper"> <h2>Search all travel deals, in one go</h2> <h1> HOTEL </h1> </div> </header> <main class="main1"> <div id="body_1"> <h2> Calbayog Hotel </h2> <h6> 2 Places </h6> <h4> Baypark Hotel </h4> <div class="gallery1"> <div class="gallery"> <img id="myImg" src="Pics&Video/Western Samar/Calbayog/Baypark/calbayog1.jpg" width="600" height="400"> </div> <div class="gallery"> <img id="myImg" src="Pics&Video/Western Samar/Calbayog/Baypark/calbayog2.jpg" width="600" height="400"> </div> <div class="gallery"> <img id="myImg" src="Pics&Video/Western Samar/Calbayog/Baypark/calbayog3.jpg" width="600" height="400"> </div> <div class="gallery"> <img id="myImg" src="Pics&Video/Western Samar/Calbayog/Baypark/calbayog4.jpg" width="600" height="400"> </div> <div id="myModal" class="modal"> <!-- The Close Button --> <span class="close">×</span> <!-- Modal Content (The Image) --> <img class="modal-content" id="img04"> <!-- Modal Caption (Image Text) --> <div id="caption"></div> </div> </div> <div class="btn"> View </div> <div class="text4"> <h4> Ciriaco Hotel </h4> </div> <div class="gallery2"> <div class="gallery"> <img src="Pics&Video/Western Samar/Calbayog/Ciriaco/ciriaco1.jpg" alt="Cinque Terre" width="600" height="400"> </div> <div class="gallery"> <img src="Pics&Video/Western Samar/Calbayog/Ciriaco/ciriaco2.jpg" alt="Forest" width="600" height="400"> </div> <div class="gallery"> <img src="Pics&Video/Western Samar/Calbayog/Ciriaco/ciriaco3.jpg" alt="Cinque Terre" width="600" height="400"> </div> <div class="gallery"> <img src="Pics&Video/Western Samar/Calbayog/Ciriaco/ciriaco4.jpg" alt="Forest" width="600" height="400"> </div> </div> <div class="btn2"> View </div> </div> </main > <footer style="background: #1a75ff;"> <div style="text-align: center; margin-left: 40%; margin-top: 30px; font-family: courier new;"> #2019 Calbayog Tourism. All rights resereved. </div> </footer> </body> </html>
First you have to move your scripts inside document.ready. They are accessing DOM elements before rendering is completed. Then you have to move the modal up. Do something like this and you'll see the modal move up. $("#img01").css({position:"absolute", "top": "0px"}) Then you can proceed :)
automatic slider animation not working
I recently implemented an automatic slider code for my slider in my website, however, it's not working for some reason. The code for the slider animation in the CSS style sheet is near the bottom. I was wondering if anybody could help me in solving the problem with my code. Here is a picture of my slider, just want the images of the bikes to move automatically. HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Croydon Cycles</title> <link rel="stylesheet" href="shop-style.css"> <link rel="shortcut icon" type="image/png" href="images/favicon.png"> <link href="https://fonts.googleapis.com/css?family=Karla" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://code.jquery.com/jquery-3.3.1.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="parallax.min.js"></script> </head> <!DOCTYPE html> <html lang="en"> <body> <div class="wrapper"> <header> <nav> <div class="menu-icon"> <i class="fa fa-bars fa-2x"></i> </div> <div class="logo"> Croydon Cycles </div> <div class="menu"> <ul> <li>Home</li> <li>Location</li> <li>Shop</li> <li>Contact</li> </ul> </div> </nav> </header> <div class="slider"> <div class="slideshow-container"> <div class="myslides fade"> <div class="numbers">1 / 4</div> <div class="slider-pic"><img class="Fit" src="images/slider-1.jpg"></div> <div class="caption">Kona Lanai 27.5" 2018 Mountain bike</div> </div> <div class="myslides fade"> <div class="numbers">2 / 4</div> <div class="slider-pic"><img class="Fit" src="images/slider-2.jpg"></div> <div class="caption">Decathlon B'twin Rockrider 520S Full Suspension Mountain Bike</div> </div> <div class="myslides fade"> <div class="numbers">3 / 4</div> <div class="slider-pic"><img class="Fit" src="images/slider-3.jpg"></div> <div class="caption">Ribble Aero 883 Carbon Road Bike - Matte Black</div> </div> <div class="myslides fade"> <div class="numbers">4 / 4</div> <div class="slider-pic"><img class="Fit" src="images/slider-4.jpg"></div> <div class="caption">Lapierre Overvolt AM700i</div> </div> <a class="prev" onclick="plusSlides(-1)">❮</a> <a class="next" onclick="plusSlides(1)">❯</a> </div> </div> <br> <div style="text-align:center"> <span class="dots" onclick="currentSlide(1)"></span> <span class="dots" onclick="currentSlide(2)"></span> <span class="dots" onclick="currentSlide(3)"></span> <span class="dots" onclick="currentSlide(4)"></span> </div> <script type="text/javascript"> var slideIndex = 1; showSlide(slideIndex); function plusSlides(n){ showSlide(slideIndex += n); } function currentSlide(n) { showSlide(slideIndex = n); } function showSlide(n){ var i; var slides = document.getElementsByClassName("myslides"); var dots = document.getElementsByClassName("dots"); if (n > slides.length) { slideIndex = 1}; if (n < 1) { slideIndex = slides.length}; for (i=0;i<slides.length;i++) { slides[i].style.display = "none"; }; for (i=0;i<dots.length;i++) { dots[i].className = dots[i].className.replace(" active",""); }; slides[slideIndex-1].style.display = "block"; dots[slideIndex-1].className += " active"; } </script> <div class="content"> </div> </div> <script type="text/javascript"> // Menu-toggle button $(document).ready(function() { $(".menu-icon").on("click", function() { $("nav ul").toggleClass("showing"); }); }); // Scrolling Effect $(window).on("scroll", function() { if($(window).scrollTop()) { $('nav').addClass('black'); } else { $('nav').removeClass('black'); } }) </script> </body> </html> CSS: html, body { margin: 0; padding: 0; width: 100%; font-family: verdana,sans-serif; margin: 0; font-family: "Helvetica Neue",sans-serif; font-weight: lighter; } header { width: 100%; height: 60px; background: url(hero.jpg) no-repeat 50% 50%; background-size: cover; } .content { width: 94%; margin: 4em auto; font-size: 20px; line-height: 30px; text-align: justify; } .logo { line-height: 60px; position: fixed; float: left; margin: 16px 46px; color: #fff; font-weight: bold; font-size: 20px; letter-spacing: 2px; } nav { position: fixed; width: 100%; line-height: 60px; z-index:2; } nav ul { line-height: 60px; list-style: none; background: rgba(0, 0, 0, 0); overflow: hidden; color: #fff; padding: 0; text-align: right; margin: 0; padding-right: 40px; transition: 1s; } nav.black ul { background: #000; } nav ul li { display: inline-block; padding: 16px 40px;; } nav ul li a { text-decoration: none; color: #fff; font-size: 16px; } .menu-icon { line-height: 60px; width: 100%; background: #000; text-align: right; box-sizing: border-box; padding: 15px 24px; cursor: pointer; color: #fff; display: none; } #media(max-width: 786px) { .logo { position: fixed; top: 0; margin-top: 16px; } nav ul { max-height: 0px; background: #000; } nav.black ul { background: #000; } .showing { max-height: 34em; } nav ul li { box-sizing: border-box; width: 100%; padding: 24px; text-align: center; } .menu-icon { display: block; } } body{ font-family: verdana,sans-serif; margin: 0; } .slideshow-container{ width: 100%; position: relative; margin: auto; } .numbers{ position: absolute; top: 0; color: #f2f2f2; padding: 8px 12px; font-size: 12px; } .myslides{ display: none; } .prev , .next{ position: absolute; top: 50%; font-size: 18px; font-weight: bold; padding: 16px; margin-top: -22px; border-radius: 0 3px 3px 0; color: black; cursor: pointer; } .next{ right: 0; border-radius: 3px 0 0 3px; } .prev:hover,.next:hover{ background-color: rgba(0,0,0,0.8); } .caption{ text-align: center; position: absolute; bottom: 8px; width: 100%; color: black; font-size: 15px; padding: 8px 22px; left:-2%; } .dots{ width: 13px; height: 13px; background: gray; display: inline-block; border-radius: 50%; cursor: pointer; } .fade{ animation-name:fade; animation-duration:1.5s; } #keyframes fade{ from {opacity: 0.4;} to {opacity: 1;} } .active, .dot:hover { background-color: #333; } .slider-pic { display: grid; height: 100%; z-index:0; } .Fit { max-width: 100%; max-height: 100vh; margin: auto; z-index:0; } #keyframes slider{ 0%{ left: 0; } 20%{ left: 0; } 25%{ left: -100%; } 45%{ left: -100%; } 50%{ left: -200%; } 70%{ left: -200%; } 75%{ left: -300%; } 95%{ left: -300%; } 100%{ left: -400%; } } #slider { overflow: hidden; } #slider figure img { width:20%; float: left; } #slider figure { position: relative; width: 500%; margin:0; left:0; animation: 20s slider infinite }
Add this instruction in your JS code: $(document).ready(function() { $(".menu-icon").on("click", function() { $("nav ul").toggleClass("showing"); }); // add this instruction ! setTimeout(function() {plusSlides(1) }, 1000) }) Herem the method slidePlus is called every 1000ms
Image transition fade
So I'm having a bit of an issue with my image gallery. I want my images to fade to the next or previous image when I press the prev/next buttons. But I also have a toggle feature that when you click on the image, it changes to a different one. The toggle works for the first two images, but I lost the fade in transition. What can I do so I can have both the toggle and the fade in? If I change the javascript code from slides[i].style.display = "none"; slides[slideIndex-1].style.display = "block" to slides[i].style.opacity = "0"; slides[slideIndex-1].style.opacity = "1"; the fade in transition works, but I lose the toggle effect. Here's the codepen: https://codepen.io/GabriellaFarfan/pen/VBYQGy. var slideIndex = 1; showSlide(slideIndex); function plusSlides(n){ showSlide(slideIndex += n); } function currentSlide(n) { showSlide(slideIndex = n); } function showSlide(n){ var i; var slides = document.getElementsByClassName("myslides"); if (n > slides.length) { slideIndex = 1}; if (n < 1) { slideIndex = slides.length}; for (i=0;i<slides.length;i++) { slides[i].style.display = "none"; }; slides[slideIndex-1].style.display = "block"; } function toggleImage(id) { var image = document.getElementById(id); image.style.display = image.style.display == "none" ? "block" : "none"; } function toggleBoth() { toggleImage('image1') toggleImage('image2') toggleImage('image3') toggleImage('image4') } $(document).ready(function(){ $(".next").click(function(){ $("") }); }); * { margin: 0; padding: 0; list-style-type:none; } body{ margin: 0; font-size: 100%; background-color: #232324; height: 100vh; } .header { overflow: auto; background-color: #ECAAAC; } .logo { float: left; padding-top: 1em; width: 20%; text-align: center; font-family: 'Allerta', sans-serif; text-transform: uppercase; font-weight: 700; } .logo a { text-decoration: none; font-size: 1em; color: black; } .nav { background-color: #232324; padding-top: 1em; padding-bottom: 1em; width: 80%; float: right; } li { display: inline-block !important; border-right: 1px solid #656568; padding-right: 1.5em; padding-left: 1.5em; } li:last-child{ border-right: none; } li a { text-decoration: none; text-align: center; color: white; font: normal 62.5% "proxima-nova-alt", Helvetica, Arial, sans-serif; text-transform: uppercase; font-weight: 700; letter-spacing: 1px; } li a:hover { color: #ECAAAC; } .text { background-color: black; padding: .75em 0 .75em 0; } p { color: #656568; text-align: center; font-size: 1em; font: italic 80% "proxima-nova-alt", Helvetica, Arial, sans-serif; } #slideshow-container{ position: relative; margin: auto; background-color: black; overflow: hidden; padding-bottom: 2.5em; height: 1000px !important; } #slideshow-container img{ display: block; margin: 0 auto; max-width: 100%; position: relative; height: 960px; } .myslides { position: absolute; margin-left: auto; margin-right: auto; left: 0; right: 0; opacity: 1; -webkit-transition: opacity .5s ease; transition: opacity .5s ease; } .prev , .next{ position: absolute; top: 50%; font-size: 30px; font-weight: bold; padding: 16px; margin-top: -22px; color: #fff; cursor: pointer; z-index: 1; } .next{ right: 0; } .prev:hover,.next:hover{ /* color: #b0d5d0 ; */ /* background-color: rgba(0,0,0,0.8); */ } .caption{ text-align: center; position: absolute; width: 100%; color: #f2f2f2; text-shadow: 2px 2px 4px black; font: normal 62.5% "proxima-nova-alt", Helvetica, Arial, sans-serif; text-transform: uppercase; font-weight: 700; letter-spacing: 1px; padding-top: 1.25em; } #media(max-width: 798px) { #slideshow-container { height: 640px !important; } #slideshow-container img { max-height: 600px !important; display: block; margin: 0 auto; max-width: 100%; } .nav { width: 75%; } .logo { width: 25%; text-align: center; } .logo a { font-size: .75em; } li { padding-right: .75em !important; padding-left: .75em !important; } } #media(max-width: 468px) { #slideshow-container { height: 440px !important; } #slideshow-container img{ max-height: 400px !important; display: block; margin: 0 auto; max-width: 100%; } .nav { width: 65%; } .logo { width: 35%; text-align: center; } } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!---Images not owned by me ---> <link href="https://fonts.googleapis.com/css?family=Allerta" rel="stylesheet"> <div class="header"> <div class="logo"> Gabriella Farfan </div> <div class="nav"> <ul> <li>Portfolio</li> <li>About</li> <li>Contact</li> </ul> </div> </div> <div id="slideshow-container"> <div class="text"> <p>Click on the image to see the before and after</p> </div> <div class="myslides fade"> <div> <img id="image1" onclick="toggleBoth()" src="http://www.hestetika.it/wp-content/uploads/2016/10/stevemccurry_5.jpg"> <img id="image2" onclick="toggleBoth()" style="display:none;" src="https://static.boredpanda.com/blog/wp-content/uploads/2014/12/Top-10-photographers-for-travel-portraits27__700.jpg"> </div> <div class="caption">Text 1</div> </div> <div class="myslides fade"> <div> <img id="image3" onclick="toggleBoth()" src="https://i.pinimg.com/736x/2f/7a/33/2f7a33e82f03de319faa0663371e2609--interesting-faces-freckles.jpg"> <img id="image4" onclick="toggleBoth()" style="display:none;" src="http://cdn3.spiegel.de/images/image-945792-galleryV9-buud-945792.jpg"> </div> <div class="caption">Text 2</div> </div> <div class="myslides fade"> <div> <img src="https://media.discordapp.net/attachments/327123793040637952/436369548996902913/nwts_ariana.jpg?width=1050&height=1050"> </div> <div class="caption">Text 3</div> </div> <div class="myslides fade"> <div> <img src="http://jmacpratt.weebly.com/uploads/1/2/0/1/12013129/portrait2_orig.jpg"> </div> <div class="caption">Text 4</div> </div> <a class="prev" onclick="plusSlides(-1)">❮</a> <a class="next" onclick="plusSlides(1)">❯</a> </div> <br>
Apart from making display none and display block try using visibility visible and hidden with transition:0.5s and opacity 0 / 1
Add text pop up on link click
MY website is currently under construction so im trying to add a little pop up on the header links that says "coming soon" or something like that. You click it and it just pops up near the link. This is the tutorial i was following but cant get it to work with my own code. So ill take anything at this point. https://www.w3schools.com/howto/howto_js_popup.asp Id like something where all i have to do is add a certain class to each link and it just work once that class is added or something like that seems to me to be the best. so idealy id like to add it to the about us, our work and services button. <ul class="nav"> <div class="new"> <li>HOME</li> <li>ABOUT US</li> <li>OUR WORK</li> <li>SERVICES</li> </div> </ul> #import url('https://fonts.googleapis.com/css?family=Roboto'); #import url('https://fonts.googleapis.com/css?family=Roboto:bold'); #import url('https://fonts.googleapis.com/css?family=Roboto:100'); #import url('https://fonts.googleapis.com/css?family=Roboto:600'); #font-face { font-family: "roboto"; src: url('https://fonts.googleapis.com/css?family=Roboto'); } html, body { margin: 0; padding: 0; height: 100%; width: 100%; top: 0; background-image: url('images/bg.png'); background-size: cover; background-position: center; background-repeat: no-repeat; background-color:#e0e0e0; } .logo { width: 150px; fill: white; display: block; position: relative; padding: 23px 0px 0px 50px; } .logo svg { position: absolute; top: 0px; right: 0px; } #hireus { position: absolute; top: 0; right: 0; padding: 3px; font-family: proxima nova; font-size: 12px; text-decoration: none; color: white; margin: 27px 50px 0px 0px; text-decoration: none; z-index: 10; } .intro { height: 100%; width: 100%; margin: auto; display: table; /* top: 0; background-image: url('images/bg.png'); background-size: cover; background-position: center; background-repeat: no-repeat; */ } .intro .inner { display: table-cell; vertical-align: middle; width: 100%; max-width: none; } /* was ul */ .nav { list-style-type: none; overflow: hidden; position: absolute; top: 0; left: 0; opacity: 0.8; display: table; margin: 0; width: 100%; text-align: center; padding: 0 } li { /* width: 120px; height: 40px; */ margin: 0px 0px; display: inline-block; padding: 0; font-family: proxima nova; font-size: 10px; text-decoration: none; } .new a { display: block; /* width: 120px; height: 40px; */ /* line-height: 40px; */ text-decoration: none; text-align: center; color: white; /* margin: 20px 20px; */ margin: 32px 20px 0px 20px; } .content { max-width: 1200px; margin: 0 auto; text-align: center; padding-bottom: 7%; } .content h1 { font-family: proxima nova; font-size: 520%; font-weight: bold; color: white; margin: 0; padding-bottom: 3px; } .content p { font-family: proxima nova; font-size: 12px; font-weight: 100; color: white; margin: 0 auto; max-width: 420px; padding-bottom: 25px; } .btn { font-family: proxima nova; font-size: 14px; font-weight: bold; color: white; text-decoration: none; border: solid 1px white; /* padding: 10px 100px; */ border-radius: 60px; transition: all 0.5s; width: 160px; display: inline-block; text-align: center; padding-top: 13px; padding-bottom: 13px; } .btn:hover { color: #b0ccff; border: solid 1px #b0ccff; } .btn2 { font-family: proxima nova; font-size: 14px; font-weight: bold; color: white; text-decoration: none; border: solid 1px #0B315C; /* padding: 10px 100px; */ border-radius: 60px; transition: all 0.5s; width: 160px; background-color: #0B315C; display: inline-block; text-align: center; padding-top: 13px; padding-bottom: 13px; margin-left: 30px; -webkit-box-shadow: 0px 0px 20px black rgba(0, 0, 0, 0.5); -moz-box-shadow: 0px 0px 20px black rgba(0, 0, 0, 0.5); box-shadow: 0px 0px 20px black rgba(0, 0, 0, 0.5); } .btn2:hover { color: #b0ccff; border: solid 1px #b0ccff; } #scroll { color: green; } .title { font-family: proxima nova; font-size: 50px; font-weight: 600; color: black; text-align: center; margin-top: 60px; padding-bottom: 2px; } .subtitle { font-family: proxima nova; font-size: 12px; font-weight: 200; color: #9D9D9D; text-align: center; margin-top: -45px; padding-bottom: 2px; } #second { border-bottom: 1px solid #E6E6E6; width: 480px; margin: auto; } #Layer_1 { width: 100px; height: 100px; } #group2 {} .whatwedo { text-align: center; width: 100%; margin-top: 100px; } .subject { text-align: center; width: 300px; display: inline-block; margin: 0px 50px; } .subject img{ width: 100px; } .subject h2 { font-family: proxima nova; font-size: 20px; font-weight: 600; color: black; margin-bottom: 12px; } .desc { font-family: proxima nova; font-size: 12px; font-weight: 200; color: #9D9D9D; } .group3 { position: relative; text-align: center; color: white; margin-top: 90px; } .centered { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: proxima nova; font-size: 24px; font-weight: 100; color: white; width: 550px; } form { display: table; margin: 0 auto; } #forth { width: 100%; } #forth h2{ margin-bottom: 20px; } input[type=text], select { width: 400px; padding: 13px 20px; margin: 8px 0; display: inline-block; border-radius: 30px; box-sizing: border-box; font-family: proxima nova; font-size: 14px; } input[type=submit] { width: 160px; background-color: #4CAF50; color: white; padding: 13px 20px; margin: 8px 0; border: none; border-radius: 30px; cursor: pointer; background-color: #0B315C; font-family: proxima nova; font-size: 14px; font-weight: bold; position: relative; bottom: 42px; margin: -9px 0px 0px 240px; } .email-form { width: 400px; } .email-form input { border: 0; box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.2); } #hi{ background-color: #F9F9F9; margin-top: -64px; padding-top: 150px; padding-bottom: 120px; } footer { background-color: #30659B; width: 100vw; } .logo2 { width: 150px; fill: white; display: block; } .nav2 { padding:0; list-style-type: none; color: white; display: flex; /*Generates a flexbox layout with default flex direction as row */ width: 100%; /* Not really required */ height:100px; align-items: center; /*Aligns contents vertically */ justify-content: space-around; margin: 0px; } li { padding:0; font-family: proxima nova; font-size: 10px; text-decoration: none; text-align:center; margin:5px; } li:first-child{ margin-left:100px; } li:last-child{ margin-right:100px; } li a { text-decoration: none; color: white; } /*--- Media Queries --*/ #media screen and (max-width: 900px) { .content { padding-bottom: 10%; } .content h1 { font-size: 400% } .btn { font-size: 110%; padding: 9px 43px; } } #media screen and (max-width: 768px) { .content { padding-bottom: 12%; } .content h1 { font-size: 300% } .btn { font-size: 100%; padding: 9px 43px; } } #media screen and (max-width: 480px) { .content { padding-bottom: 14%; } .content h1 { font-size: 300% } .btn { font-size: 100%; padding: 10px 44px; } } <!DOCTYPE html> <head> <title>Launchpad | Web design and marketing</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link href="css/animate.css" rel="stylesheet"/> <link href="css/waypoints.css" rel="stylesheet"/> <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"> <link rel="icon" href="images/favicon.ico" type="image/x-icon"> <script src="js/jquery.waypoints.min.js" type="text/javascript"></script> <script src="js/waypoints.js" type="text/javascript"></script> </head> <body> <div class="logo"> <svg class="logo" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 268 50"><title>Artboard 1</title><path d="M46.26,10.5h6.46V35.17H65.55v5.69H46.26Z"/><path d="M82.8,38.59a9.1,9.1,0,0,1-7,2.82c-3.5,0-7.65-2.37-7.65-7.28,0-5.14,4.14-7,7.65-7,2.91,0,5.51.91,7,2.69v-3c0-2.23-1.91-3.69-4.82-3.69a9.25,9.25,0,0,0-6.42,2.59l-2.18-3.87A14.42,14.42,0,0,1,79,18.33c5,0,9.6,2,9.6,8.33v14.2H82.8Zm0-5.74a5.78,5.78,0,0,0-4.64-1.91c-2.28,0-4.14,1.23-4.14,3.32s1.87,3.23,4.14,3.23a5.78,5.78,0,0,0,4.64-1.91Z"/><path d="M109.15,38.08a10.29,10.29,0,0,1-7.74,3.32c-4.82,0-7.1-2.64-7.1-6.92V18.88h5.78V32.21c0,3,1.59,4.05,4.05,4.05a6.47,6.47,0,0,0,5-2.5V18.88h5.78v22h-5.78Z"/><path d="M135.5,27.57c0-3-1.59-4.1-4.05-4.1a6.26,6.26,0,0,0-5,2.59V40.86h-5.78v-22h5.78v2.87a10.07,10.07,0,0,1,7.69-3.41c4.82,0,7.15,2.73,7.15,7V40.86H135.5Z"/><path d="M157.26,18.33c4.51,0,7.24,2,8.69,4l-3.78,3.5a5.44,5.44,0,0,0-4.64-2.37c-3.5,0-6,2.55-6,6.37s2.46,6.42,6,6.42a5.55,5.55,0,0,0,4.64-2.37L166,37.4c-1.46,2-4.19,4-8.69,4-6.78,0-11.65-4.78-11.65-11.56S150.48,18.33,157.26,18.33Z"/><path d="M184.61,27.48c0-3-1.59-4-4.1-4a6.4,6.4,0,0,0-5,2.59V40.86h-5.78V10.5h5.78V21.74a10.17,10.17,0,0,1,7.74-3.41c4.82,0,7.15,2.64,7.15,6.92V40.86h-5.78Z"/><path d="M196.12,49.24V18.88h5.78v2.78a8.49,8.49,0,0,1,6.78-3.32c5.64,0,9.74,4.19,9.74,11.52s-4.1,11.56-9.74,11.56A8.4,8.4,0,0,1,201.9,38v11.2Zm10.74-25.76a6.47,6.47,0,0,0-5,2.5v7.78a6.62,6.62,0,0,0,5,2.5c3.32,0,5.55-2.59,5.55-6.42S210.19,23.47,206.86,23.47Z"/><path d="M235.94,38.59a9.1,9.1,0,0,1-7,2.82c-3.51,0-7.65-2.37-7.65-7.28,0-5.14,4.14-7,7.65-7,2.91,0,5.51.91,7,2.69v-3c0-2.23-1.91-3.69-4.82-3.69a9.25,9.25,0,0,0-6.42,2.59l-2.18-3.87a14.42,14.42,0,0,1,9.6-3.46c5,0,9.6,2,9.6,8.33v14.2h-5.78Zm0-5.74a5.78,5.78,0,0,0-4.64-1.91c-2.28,0-4.14,1.23-4.14,3.32s1.87,3.23,4.14,3.23a5.78,5.78,0,0,0,4.64-1.91Z"/><path d="M262.57,38.08a8.62,8.62,0,0,1-6.78,3.32c-5.55,0-9.74-4.19-9.74-11.51s4.14-11.56,9.74-11.56a8.47,8.47,0,0,1,6.78,3.37V10.5h5.83V40.86h-5.83Zm0-12.11a6.36,6.36,0,0,0-5-2.5c-3.28,0-5.55,2.59-5.55,6.42s2.28,6.37,5.55,6.37a6.36,6.36,0,0,0,5-2.5Z"/><path d="M7.56,38.52l8.13,10.73a1.41,1.41,0,0,0,2.16,0L26,38.52a1.34,1.34,0,0,0-.56-2L18.53,33A4,4,0,0,0,15,33l-6.89,3.5A1.34,1.34,0,0,0,7.56,38.52Z"/><path d="M30.31,14.15,18.12.82a1.91,1.91,0,0,0-2.7,0L3.23,14.15a4,4,0,0,0-1,2.16L-.38,34.52c-.13.9,1,1.53,1.93,1.07L4.29,34.2l12.48-6.37L29.25,34.2,32,35.59c.92.47,2.06-.17,1.93-1.07l-2.57-18.2A4,4,0,0,0,30.31,14.15Z"/></svg> </div> <a id="hireus" href="/">HIRE US</a> <ul class="nav"> <div class="new"> <li>HOME</li> <li>ABOUT US</li> <li>OUR WORK</li> <li>SERVICES</li> </div> </ul> <section class="intro"> <div class="inner"> <div class="content"> <section class="os-animation" data-os-animation="fadeInUp" data-os-animation-delay="0.2s"> <h1>Welcome to Launchpad</h1> <p>We are a creative agency who specializes in digital marketing and graphic design. Let us launch your business to the next level!</p> </section> <section class="os-animation" data-os-animation="fadeInUp" data-os-animation-delay="0.7s"> <a class="btn" href="#">Hire Us</a> <a class="btn2" href="#">Learn More</a> </section> </div> </div> </section> <div id="second"> <h2 class="title">What we do</h2> <p class="subtitle">Let us take your buisness to the next level.</p> </div> <div class="group2"> <div class="whatwedo"> <div class="subject" id="customdesign"> <img src="images/customdesign.svg" alt="Custom Design"> <h2 class="title2">Custom Design</h2> <p class="desc">Lorem ipsum dolor sit amet, scripta posidonium per ex. Duo ad unum graece luptatum, ius in dolores deleniti posidonium. </p> </div> <div class="subject" id="contentmarketing"> <img src="images/contentmarketing.svg" alt="Content Mrketing"> <h2 class="title2">Content Marketing</h2> <p class="desc">Lorem ipsum dolor sit amet, scripta posidonium per ex. Duo ad unum graece luptatum, ius in dolores deleniti posidonium. </p> </div> <div class="subject" id="emailmarketing"> <img src="images/emailmarketing.svg" alt="Email Marketing"> <h2 class="title2">Email Marketing</h2> <p class="desc">Lorem ipsum dolor sit amet, scripta posidonium per ex. Duo ad unum graece luptatum, ius in dolores deleniti posidonium. </p> </div> </div> </div> <div class="group3"> <img src="images/testimonialbg.png" alt="Norway" style="width:100%;"> <div class="centered">“The team at Launchpad exceeded our expectations! They have a bright future ahead of them.”<br> <span style="font-weight: 600;">Sam Molloy, Unmatched Masonry</span></div> </div> <!-- <div id="second"> <h2 class="title">Our work</h2> <p class="subtitle">Nervous about taking off? Here's the portfolio.</p> </div> --> <div id="hi"> <div id="forth"> <h2 class="title">Lets get in touch</h2> <form action="mailto:contact#madebylaunchpad.com" method="post" enctype="text/plain" class="email-form"> <input type="text" name="mail" placeholder="Your email address"><br> <input type="submit" value="Lets talk"> </form> </div> </div> <footer> <ul class="nav2"> <li class="li2">ABOUT US</li> <li class="li2">OUR WORK</li> <li class="li2">SERVICES</li> <li> <div class="logo2"> <svg class="logo2" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 268 50"><title>Artboard 1</title><path d="M46.26,10.5h6.46V35.17H65.55v5.69H46.26Z"/><path d="M82.8,38.59a9.1,9.1,0,0,1-7,2.82c-3.5,0-7.65-2.37-7.65-7.28,0-5.14,4.14-7,7.65-7,2.91,0,5.51.91,7,2.69v-3c0-2.23-1.91-3.69-4.82-3.69a9.25,9.25,0,0,0-6.42,2.59l-2.18-3.87A14.42,14.42,0,0,1,79,18.33c5,0,9.6,2,9.6,8.33v14.2H82.8Zm0-5.74a5.78,5.78,0,0,0-4.64-1.91c-2.28,0-4.14,1.23-4.14,3.32s1.87,3.23,4.14,3.23a5.78,5.78,0,0,0,4.64-1.91Z"/><path d="M109.15,38.08a10.29,10.29,0,0,1-7.74,3.32c-4.82,0-7.1-2.64-7.1-6.92V18.88h5.78V32.21c0,3,1.59,4.05,4.05,4.05a6.47,6.47,0,0,0,5-2.5V18.88h5.78v22h-5.78Z"/><path d="M135.5,27.57c0-3-1.59-4.1-4.05-4.1a6.26,6.26,0,0,0-5,2.59V40.86h-5.78v-22h5.78v2.87a10.07,10.07,0,0,1,7.69-3.41c4.82,0,7.15,2.73,7.15,7V40.86H135.5Z"/><path d="M157.26,18.33c4.51,0,7.24,2,8.69,4l-3.78,3.5a5.44,5.44,0,0,0-4.64-2.37c-3.5,0-6,2.55-6,6.37s2.46,6.42,6,6.42a5.55,5.55,0,0,0,4.64-2.37L166,37.4c-1.46,2-4.19,4-8.69,4-6.78,0-11.65-4.78-11.65-11.56S150.48,18.33,157.26,18.33Z"/><path d="M184.61,27.48c0-3-1.59-4-4.1-4a6.4,6.4,0,0,0-5,2.59V40.86h-5.78V10.5h5.78V21.74a10.17,10.17,0,0,1,7.74-3.41c4.82,0,7.15,2.64,7.15,6.92V40.86h-5.78Z"/><path d="M196.12,49.24V18.88h5.78v2.78a8.49,8.49,0,0,1,6.78-3.32c5.64,0,9.74,4.19,9.74,11.52s-4.1,11.56-9.74,11.56A8.4,8.4,0,0,1,201.9,38v11.2Zm10.74-25.76a6.47,6.47,0,0,0-5,2.5v7.78a6.62,6.62,0,0,0,5,2.5c3.32,0,5.55-2.59,5.55-6.42S210.19,23.47,206.86,23.47Z"/><path d="M235.94,38.59a9.1,9.1,0,0,1-7,2.82c-3.51,0-7.65-2.37-7.65-7.28,0-5.14,4.14-7,7.65-7,2.91,0,5.51.91,7,2.69v-3c0-2.23-1.91-3.69-4.82-3.69a9.25,9.25,0,0,0-6.42,2.59l-2.18-3.87a14.42,14.42,0,0,1,9.6-3.46c5,0,9.6,2,9.6,8.33v14.2h-5.78Zm0-5.74a5.78,5.78,0,0,0-4.64-1.91c-2.28,0-4.14,1.23-4.14,3.32s1.87,3.23,4.14,3.23a5.78,5.78,0,0,0,4.64-1.91Z"/><path d="M262.57,38.08a8.62,8.62,0,0,1-6.78,3.32c-5.55,0-9.74-4.19-9.74-11.51s4.14-11.56,9.74-11.56a8.47,8.47,0,0,1,6.78,3.37V10.5h5.83V40.86h-5.83Zm0-12.11a6.36,6.36,0,0,0-5-2.5c-3.28,0-5.55,2.59-5.55,6.42s2.28,6.37,5.55,6.37a6.36,6.36,0,0,0,5-2.5Z"/><path d="M7.56,38.52l8.13,10.73a1.41,1.41,0,0,0,2.16,0L26,38.52a1.34,1.34,0,0,0-.56-2L18.53,33A4,4,0,0,0,15,33l-6.89,3.5A1.34,1.34,0,0,0,7.56,38.52Z"/><path d="M30.31,14.15,18.12.82a1.91,1.91,0,0,0-2.7,0L3.23,14.15a4,4,0,0,0-1,2.16L-.38,34.52c-.13.9,1,1.53,1.93,1.07L4.29,34.2l12.48-6.37L29.25,34.2,32,35.59c.92.47,2.06-.17,1.93-1.07l-2.57-18.2A4,4,0,0,0,30.31,14.15Z"/></svg> </div></li> <li class="li3">TWITTER</li> <li class="li3">FACEBOOK</li> <li class="li3">INSTAGRAM</li> </ul> </footer> </body> </html>
Here's the code working: function myFunction() { var popup = document.getElementById("myPopup"); popup.classList.toggle("show"); } .popup { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .popup .popuptext { visibility: hidden; width: 160px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 8px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -80px; } .popup .popuptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } .popup .show { visibility: visible; -webkit-animation: fadeIn 1s; animation: fadeIn 1s; } #-webkit-keyframes fadeIn { from {opacity: 0;} to {opacity: 1;} } #keyframes fadeIn { from {opacity: 0;} to {opacity:1 ;} } <body style="text-align:center"> <h2>Popup</h2> <div class="popup" onclick="myFunction()">Click me to toggle the popup! <span class="popuptext" id="myPopup">A Simple Popup!</span> </div> </body>
I built a pretty easy example for you and I'll run you through the code here. First here it is in action: var selector = document.getElementById('showHide'); selector.onclick = function(){ var show = document.getElementById('hidden'); show.style.display = "block" }; <ul class="nav"> <div class="new"> <li id="showHide">HOME</li> <li id='hidden' style='display: none;'>Hello</li> <li>ABOUT US</li> <li>OUR WORK</li> <li>SERVICES</li> </div> </ul> This is going to be your nav bar. As you can see i made some changes. I gave your home button an id so that we can call it later. I also added a new <li> tag that is hidden from site by "display: none". <ul class="nav"> <div class="new"> <li id="showHide"><a href="/" >HOME</a></li> <li id='hidden' style='display: none;'>Hello</li> <li>ABOUT US</li> <li>OUR WORK</li> <li>SERVICES</li> </div> </ul> Here is the magic var selector = document.getElementById('showHide'); selector.onclick = function(){ var show = document.getElementById('hidden'); show.style.display = "block" }; At the top we create a selector variable to tell it what we want to target, which for us will be the Home button. Below that we write a function that triggers when our selector is clicked. When it is triggered we define what we want to change(in this case that would be the element with the id of "hidden"). After that we simply edit it's display property to show.