I'm trying to add a SharePoint Library as a source for the images in a custom slideshow created using JavaScript, as well as add the Title to be shown along with each image. Here's what I have so far, it is working, but is hardcoded:
<!DOCTYPE html>
<html>
<head>
<title>Slede-Show</title>
</head>
<body>
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="URL TO PIC" alt="First" class="slide" />
<img src="URL TO PIC 2" alt="Second" class="slide" />
<img src="URL TO PIC 3" alt="Third" class="slide" />
</div>
</div>
</body>
</html>
<style type="text/css">
html,body {
margin: 0;
padding: 0;
}
.slider {
width: 600px;
margin: 2em auto;
}
.slider-wrapper {
width: 100%;
height: 400px;
;
}
.slide {
float: left;
;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity 6s linear;
}
.slider-wrapper > .slide:first-child {
opacity: 1;
}
</style>
<script type="text/javascript">
(function() {
function Slideshow( element ) {
this.el = document.querySelector( element );
this.init();
}
Slideshow.prototype = {
init: function() {
this.wrapper = this.el.querySelector( ".slider-wrapper" );
this.slides = this.el.querySelectorAll( ".slide" );
this.previous = this.el.querySelector( ".slider-previous" );
this.next = this.el.querySelector( ".slider-next" );
this.index = 0;
this.total = this.slides.length;
this.timer = null;
this.action();
this.stopStart();
},
_slideTo: function( slide ) {
var currentSlide = this.slides[slide];
currentSlide.style.opacity = 1;
for( var i = 0; i < this.slides.length; i++ ) {
var slide = this.slides[i];
if( slide !== currentSlide ) {
slide.style.opacity = 0;
}
}
},
action: function() {
var self = this;
self.timer = setInterval(function() {
self.index++;
if( self.index == self.slides.length ) {
self.index = 0;
}
self._slideTo( self.index );
}, 6000);
},
stopStart: function() {
var self = this;
self.el.addEventListener( "mouseover", function() {
clearInterval( self.timer );
self.timer = null;
}, false);
self.el.addEventListener( "mouseout", function() {
self.action();
}, false);
}
};
document.addEventListener( "DOMContentLoaded", function() {
var slider = new Slideshow( "#main-slider" );
});
})();
</script>