• Skip to primary navigation
  • Skip to main content
Matthew Dunbar

Matthew Dunbar

Hire Me
  • About
  • Portfolio
  • Blog
    • General
    • HTML
    • jQuery
    • PHP
    • Optimization
  • Hire Me
You are here: Home / Archives for jQuery

jQuery

Simple jQuery Slider without Controls

February 25, 2017

The HTML



<ul id="slides">
	<li class="slide showing">Slide One</li>
	<li class="slide">Slide Two</li>
	<li class="slide">Slide Three</li>
</ul>

The CSS



#slides {
	position: relative;
	height: 300px;
	padding: 0px;
	margin: 0px;
	list-style-type: none;
	transition: 1.2s;
	color: #fff;
}
	
.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;
}

/* Optional CSS to target each slide */

.slide:nth-child(1) {
    background: red;
}

.slide:nth-child(2) {
    background: blue;
}

.slide:nth-child(3) {
    background: purple;
}

The jQuery



var slides = document.querySelectorAll('#slides .slide');
var currentSlide = 0;
var slideInterval = setInterval(nextSlide,6000);

function nextSlide() {
    slides[currentSlide].className = 'slide';
    currentSlide = (currentSlide+1)%slides.length;
    slides[currentSlide].className = 'slide showing';
}

The Result

  • Slide One
  • Slide Two
  • Slide Three

Filed Under: jQuery

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Interim pages omitted …
  • Page 8
  • Go to Next Page »
© 2025 Matthew Dunbar - All Rights Reserved Back to Top