Rotate Image using java script -
I have an list of images in, I want to rotate each image one by one.
HTML -
<div><img id="image" src="image1"/></div>
Javascript
var imageList = ["image01", "image02", "image03", "image04"];
var index = 0;
function next() {
if (index < imageList.length) {
index ++;
} else {
index = 0;
}
$('#image').attr("src", imageList[index]);
}
function previous() {
if (index > 0) {
index --;
} else {
index = imageList.length - 1;
}
$('#image').attr("src", imageList[index]);
}
Call next or previous function to rotate images.
I have an list of images in, I want to rotate each image one by one.
HTML -
<div><img id="image" src="image1"/></div>
Javascript
var imageList = ["image01", "image02", "image03", "image04"];
var index = 0;
function next() {
if (index < imageList.length) {
index ++;
} else {
index = 0;
}
$('#image').attr("src", imageList[index]);
}
function previous() {
if (index > 0) {
index --;
} else {
index = imageList.length - 1;
}
$('#image').attr("src", imageList[index]);
}
Call next or previous function to rotate images.
No comments:
Post a Comment