Created
January 21, 2018 12:50
-
-
Save abhishek-9ithub/979e6c84114e241966d52324993bb90e to your computer and use it in GitHub Desktop.
use for fadein slider using javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>JS FadeInOut Slider</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<style> | |
#slider { | |
opacity: 1; | |
transition: opacity 1s; | |
} | |
#slider.fadeOut { | |
opacity: 0; | |
} | |
html, | |
body { | |
height: 100%; | |
background: #eee; | |
} | |
.screenSaver { | |
width: 100%; | |
height: 100%; | |
background: #f8f8f8; | |
background-size: cover; | |
background-position: center; | |
background-repeat: no-repeat; | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
z-index: 99999; | |
} | |
.screenSaver > img { | |
width: 100%; | |
height: 100%; | |
object-fit: cover; | |
object-position: center; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="screenSaver"> | |
<img id="slider" src="images/wall1.jpg" /> | |
</div> | |
<div class="jumbotron text-center"> | |
<h1>My First Bootstrap Page</h1> | |
<p>Resize this responsive page to see the effect!</p> | |
</div> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-sm-4"> | |
<h3>Column 1</h3> | |
<p>Lorem ipsum dolor..</p> | |
<p>Ut enim ad..</p> | |
</div> | |
<div class="col-sm-4"> | |
<h3>Column 2</h3> | |
<p>Lorem ipsum dolor..</p> | |
<p>Ut enim ad..</p> | |
</div> | |
<div class="col-sm-4"> | |
<h3>Column 3</h3> | |
<p>Lorem ipsum dolor..</p> | |
<p>Ut enim ad..</p> | |
</div> | |
</div> | |
</div> | |
<script> | |
var imgArray = [ | |
'images/wall1.jpg', | |
'images/wall2.jpg', | |
'images/wall1.jpg'], | |
curIndex = 0; | |
imgDuration = 3000; | |
function slideShow() { | |
document.getElementById('slider').className += "fadeOut"; | |
setTimeout(function () { | |
document.getElementById('slider').src = imgArray[curIndex]; | |
document.getElementById('slider').className = ""; | |
}, 1000); | |
curIndex++; | |
if (curIndex == imgArray.length) { curIndex = 0; } | |
setTimeout(slideShow, imgDuration); | |
} | |
slideShow(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment