Jump to content

How to make photo album moving?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
xle_camry

xle_camry

    Programmer

  • Members
  • PipPipPipPip
  • 141 posts
Hello friends! Can you tell me how to make a photo album:
while pressing one button appears an image, while pressing another, appears other image.
I think it is done in Javascript.
I mean this: enter the site Doganlar | ????? ?????????? ?? DOGANLAR.BIZ, and in main page you will be able to see what i am talking about.
Thanks!

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
This does it with plain javascript, assuming the images are in the same directory of the .html file.

<html> 

<head> 

</head> 


<script type="text/javascript"> 

var imageTag;

var images;

var index;


function init(){

	imageTag = document.getElementById("image");

	images = new Array();

	images[0] = "image1.png";

	images[1] = "image2.png";

	images[2] = "image3.png";

	index = 0;

}


function next(){

	if(index == images.length-1){

		index = 0;

	} else {

		index++;

	}

	imageTag.setAttribute("src", images[index]);

}

</script> 


<body onload="init()"> 

	<img id="image" src="image1.png"/>

	<input type="button" onclick="next()" value="next"/>

</body> 

</html>    


This obviously looks ugly as crap, but with JQuery you can propably add a fadeIn of some kind on the imageTag.
And the init() becomes the $(document).ready(function(){ ... });


Edit: to have multiple buttons pointing to their image, you can do something like

....

function next(imageName){

	imageTag.setAttribute("src", imageName);

}

....

<input type="button" onclick="next('image1.png')" value="1"/>

<input type="button" onclick="next('image2.png')"" value="2"/>

<input type="button" onclick="next('image3.png')"" value="3"/>

And you can drop everything related to the images and index variables




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users