1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<script src="[#jquery#]/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
/*
* The array of images we will show
*/
var images = [
"chagall1.jpg" ,
"chagall2.jpg" ,
"chagall3.jpg"
];
/*
* The pointer to the current image in the array of images
*/
var index = Math.round((images.length - 1) * Math.random());
/*
* Initialize the page. This is called by jQuery as soon as the DOM is ready to be manipulated.
* See below how this is invoked.
*/
function init() {
placeImage(index);
}
/*
* Place the image indicated with the current index. Note the use of $() which is jQuery itself.
*/
function placeImage(index) {
$("#image").html("<img src='images/" + images[index] + "'/>");
$("#caption").html((index + 1) + " of " + images.length)
}
/*
* Convenient method to fade in and out.
*/
function fade(selector, cont) {
$(selector).fadeTo("normal", 0.0, cont);
$(selector).fadeTo("normal", 1.0);
}
/*
* Invoked by clicking on "next"
*/
function previous() {
index = (index == 0) ? images.length - 1 : index - 1;
fade("#slideshow", function() {
placeImage(index)
});
}
/*
* Invoked by clicking on "previous"
*/
function next() {
index = (index == images.length - 1) ? 0 : index + 1;
fade("#slideshow", function() {
placeImage(index)
});
}
/*
* This call is the jQuery equivalent of invoking onLoad, but it's faster
* because it doesn't wait for all the images to be fetches before invoking
*/
$(init);
</script>
|