JavaScript Slideshow With Controls and pagination
How do I make an javascript slideshow with controls and pagination?
Forked from Yaphi's Pen Basic JavaScript Slideshow without jQuery.. What is a javascript slideshow with controls and pagination? How do you make a javascript slideshow with controls and pagination? This script and codes were developed by Yaphi on 18 July 2022, Monday.
JavaScript Slideshow With Controls and pagination - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>JavaScript Slideshow With Controls and pagination</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <ul id="slides"> <li class="slide showing"></li> <li class="slide"></li> <li class="slide"></li> </ul> <div class="buttons"> <button class="controls" id="previous"><</button> <button class="controls" id="pause">❚❚</button> <button class="controls" id="next">></button> </div> <div id="pagination"> </div>
</div> <script src="js/index.js"></script>
</body>
</html>
JavaScript Slideshow With Controls and pagination - Script Codes CSS Codes
/*
essential styles:
these make the slideshow work
*/
#slides{ position: relative; height: 300px; padding: 0px; margin: 0px; list-style-type: none;
}
.slide{ position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; opacity: 0; z-index: 1; -webkit-transition: opacity 1s; -moz-transition: opacity 1s; -o-transition: opacity 1s; transition: opacity 1s;
}
.showing{ opacity: 1; z-index: 2;
}
.controls{ display: none;
}
/*
non-essential styles:
just for appearance; change whatever you want
*/
.slide{ font-size: 40px; padding: 40px; box-sizing: border-box; background: #333; color: #fff; background-size: cover;
}
/* http://unrestrictedstock.com/wp-content/uploads/snowy-winter-vignette-bokeh-night-snow-falling-free-stock-photo.jpg */
.slide:nth-of-type(1){ background-color: red; background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/snowy-winter-vignette-bokeh-night-snow-falling-free-stock-photo.jpg');
}
/* http://www.dawghousedesignstudio.com/wp-content/uploads/2010/01/25/free-stock-photos-1.jpg */
.slide:nth-of-type(2){ background-color: orange; background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/free-stock-photos-1.jpg');
}
/* http://www.stockfreeimages.com/static/homepage/waterfall-free-stock-photo-244915.jpg */
.slide:nth-of-type(3){ background-color: green; background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/waterfall-free-stock-photo-244915.jpg');
}
.controls{ background: #333; color: #fff; border: none; padding: 20px 0px; font-size: 20px; cursor: pointer; border: 2px solid #fff; margin: 10px 0px 0px 10px; width: 70px;
}
.controls:hover,
.controls:focus{ background: #eee; color: #333;
}
.container{ position: relative;
}
.buttons{ position: absolute; left: 0px; top: 0px; z-index: 10; font-size: 0px;
}
JavaScript Slideshow With Controls and pagination - Script Codes JS Codes
var controls = document.querySelectorAll('.controls');
for(var i=0; i<controls.length; i++){ controls[i].style.display = 'inline-block';
}
var slides = document.querySelectorAll('#slides .slide');
var currentSlide = 0;
var slideInterval = setInterval(nextSlide,2000);
function nextSlide(){ goToSlide(currentSlide+1);
}
function previousSlide(){ goToSlide(currentSlide-1);
}
function goToSlide(n){ slides[currentSlide].className = 'slide'; currentSlide = (n+slides.length)%slides.length; slides[currentSlide].className = 'slide showing';
}
var playing = true;
var pauseButton = document.getElementById('pause');
function pauseSlideshow(){ pauseButton.innerHTML = '►'; // play character playing = false; clearInterval(slideInterval);
}
function playSlideshow(){ pauseButton.innerHTML = '❚❚'; // pause character playing = true; slideInterval = setInterval(nextSlide,2000);
}
pauseButton.onclick = function(){ if(playing){ pauseSlideshow(); } else{ playSlideshow(); }
};
var next = document.getElementById('next');
var previous = document.getElementById('previous');
next.onclick = function(){ pauseSlideshow(); nextSlide();
};
previous.onclick = function(){ pauseSlideshow(); previousSlide();
};
(function(){ var p = document.getElementById('pagination'); var phtml = ''; for(var i=0; i<slides.length; i++){ phtml+='<button>'+(i+1)+'</button>'; } p.innerHTML = phtml; var pbuttons = p.querySelectorAll('button'); for(var i=0; i<pbuttons.length; i++){ pbuttons[i].onclick = (function(n){ return function(){ pauseSlideshow(); goToSlide(n); }; })(i); }
})();
Developer | Yaphi |
Username | yaphi1 |
Uploaded | July 18, 2022 |
Rating | 3 |
Size | 2,944 Kb |
Views | 44,528 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
RequestAnimationFrame Countdown | 1,706 Kb |
JavaScript Slideshow With Controls | 2,676 Kb |
Countdown Clock with Pause and Resume | 2,095 Kb |
Simple JavaScript Quiz | 2,708 Kb |
Handmade SVG Icons | 2,651 Kb |
Perspective Test | 1,694 Kb |
JavaScript Slideshow With Pause Button | 2,190 Kb |
Styled JavaScript Countdown Clock | 2,448 Kb |
Turn HTML into JS string | 2,028 Kb |
RequestAnimationFrame Countdown fork | 1,732 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
JavaScript constructors | Simboonlong | 2,415 Kb |
CSS3 keyframe onload animation. | Samueljseay | 1,706 Kb |
Layout | X-gyba | 4,234 Kb |
NeeilTimer | Neeilan | 2,836 Kb |
HTML5 Video Autoplay | Zivcos | 1,352 Kb |
Price table | Serluk | 5,928 Kb |
A Pen by Gregory Potdevin | GregoryPotdevin | 1,713 Kb |
Custom checkbox example | Capelo | 3,495 Kb |
Slider for stackoverflow | KKOKU | 3,222 Kb |
Stylize Stories | Jvhti | 2,465 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!