I am currently working on a website project, and i have put together this code (JavaScript) for a slider using an online YouTube tutorial.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript">
var imagecount = 1;
var total = 2;
function slide (x){
var Image = document.getElementById('img');
imagecount = imagecount + x;
if(imagecount > total){imagecount = 1;}
if(imagecount < 1){imagecount = total;}
Image.src = "images/img"+ imagecount +".png";
}
window.setInterval(function slideA () {
var Image = document.getElementById('img');
imagecount = imagecount + 1;
if(imagecount > total){ imagecount = 1;}
if(imagecount < 1){ imagecount = total;}
Image.src = "images/img"+ imagecount +".png";
},5000);
</script>
</head>
<title></title>
<body onload="slideA()" >
<div id="container">
<div id="header">
<div id="logo">
<img src="big states.png" alt="Logo">
</div>
</div>
<div id="nav">
<ul>
<li><a class="active" href="#home">HOME</a></li>
<li><a href="#menu">MENU</a></li>
<li><a href="#about">ABOUT</a></li>
<li><a href="#gallery">GALLERY</a></li>
<li><a href="#reviews">REVIEWS</a></li>
<li><a href="#contact">CONTACT</a></li>
</ul>
</div>
</div>
<div id="bgimg">
<img src="sliderbackground.jpg">
</div>
<div class="slidercontainer">
<img src="images/img1.png" id="img">
<div id="arrow-right"><img href="#" onclick="slide(1)" src="arrow-right.png" class="right" onmouseover="this.src='right-hover.png';" onmouseout="this.src='arrow-right.png';" /> </div>
<div id="arrow-left"><img href="#" onclick="slide(-1)" src="arrow-left.png" class="left" onmouseover="this.src='left-hover.png';" onmouseout="this.src='arrow-left.png';" /> </div>
</div>
</body>
</html>
However the tutorial did not show how to add transitions into the slider and that is what i need help on.
There are two transition effects i am looking for which are:
- OnLoad the image should fade in.
- The image should swipe left when changing.