Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- // Array of links to images
- var pictures = [
- "img/home/ateam.jpg",
- "img/home/electric.jpg"
- ];
- var index = 0;
- // Save the picture element
- var imgPic = $("#picture > img");
- var slidePic = $("#picture");
- // Change picture
- imgPic.attr('src', pictures[0]);
- slidePic.css("background-image", "url(" + pictures[0] + ")");
- // If you click on the picture
- $("#picture").click(function() {
- });
- // If left button is pressed
- $("#leftBtn").click(function() {
- // Change index and cycle
- index--;
- if(index < 0)
- index = pictures.length - 1;
- // Change picture
- imgPic.attr('src', pictures[index]);
- slidePic.css("background-image", "url(" + pictures[index] + ")");
- });
- // If right button is pressed
- $("#rightBtn").click(function() {
- // Change index and cycle
- index++;
- if(index >= pictures.length)
- index = 0;
- // Change picture
- imgPic.attr('src', pictures[index]);
- slidePic.css("background-image", "url(" + pictures[index] + ")");
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement