I need help creating a JavaScript slider that includes next and previous buttons. The functionality for these buttons is working properly, but I also want the slides to transition automatically.
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<body>
<h2 class="slide">Manual Slideshow</h2>
<div class="innerArea" style="max-width:800px;position:relative">
<div class="SlidePic">
<img class="" src="img_fjords.jpg" style="">
<p>Hello</p>
</div>
<div class="SlidePic">
<img src="image/oracle.png">
<p>Hello1</p>
</div>
<div class="SlidePic">
<img src="image/oracle.png">
<p>Hello2</p>
</div>
<div class="SlidePic">
<img src="img_forest.jpg">
<p>Hello3</p>
</div>
<a class="w3-btn-floating" style="position:absolute;top:45%;left:0" onclick="plusDivs(-1)">></a>
<a class="w3-btn-floating" style="position:absolute;top:45%;right:0" onclick="plusDivs(1)">
<</a>
</div>
</body>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
if(n=='')
n=1;
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
// Automatic slideshow transition after every 2 seconds
setInterval(function() {
plusDivs(1);
}, 2000);
</script>