body{
position:relative;
}
[data-slides] {
background-image: url(http://lorempixel.com/500/300/); /* Default image. */
background-repeat: no-repeat;
background-position: center top;
background-size: cover;
transition: background 1s linear;
}
/* Use additional CSS to control the `height` of `[data-slides]`, like so: */
.header-slides {
height: 500px;
border: 1px solid black;
position:relative;
}
@media all and (min-width: 48em) {
.header-slides { height: 500px; }
}
h2 {
position: absolute;
top:100px;
color: white;
font-size: 4em;
line-height: 1em;
text-align: center;
left: 0;
width: 100%;
}
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgba(20,20,20,0.8);
min-height: 30px;
position:absolute;
top:0;
left:0;
width:100%;
z-index:5;
}
ul.topnav li {float: right;}
ul.topnav li a {
display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
ul.topnav li a:hover {background-color: #111;}
ul.topnav li.icon {display: none;}
@media screen and (max-width:680px) {
ul.topnav li:not(:last-child) {display: none;}
ul.topnav li.icon {
float: right;
display: inline-block;
}
}
@media screen and (max-width:680px) {
ul.topnav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.topnav.responsive li {
float: none;
display: inline;
}
ul.topnav.responsive li a {
display: block;
text-align: left;
}
}
JavaScript
var nextimage=0;
var $slides = $('[data-slides]');
var images = $slides.data('slides');
doSlideshow();
function doSlideshow(){
if(nextimage>=images.length){nextimage=0;}
var a = $('[data-slides]');
$('[data-slides]')
.css('background-image','url("'+images[nextimage++]+'")')
.show(0, function(){
setTimeout(doSlideshow, 3000);
});
}
function myFunction() {
document.getElementsByClassName("topnav")[0].classList.toggle("responsive");
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.