Jump to content
  • 0

Смена картинок по щелчку


marusa23
 Share

Question

Помогите, пожалуйста, исправить. Нужно, чтобы картинки, когда на них щелкаешь, менялись по порядку, а не случайным образом. И чтобы слева и справа от картинки были стрелки и когда на них нажимаешь,картинка меняется на следующую.

Вот код программы:


SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "azbuka/А.gif";
images[2] = new Image();
images[2].src = "azbuka/Б.gif";
images[3] = new Image();
images[3].src = "azbuka/В.gif";
images[4] = new Image();
images[4].src = "azbuka/Г.gif";
images[5] = new Image();
images[5].src = "azbuka/Д.jpeg";
images[6] = new Image();
images[6].src = "azbuka/Е.gif";
images[7] = new Image();
images[7].src = "azbuka/Ё.gif";
images[8] = new Image();
images[8].src = "azbuka/Ж.gif";
images[9] = new Image();
images[9].src = "azbuka/З.gif";
images[10] = new Image();
images[10].src = "azbuka/И.gif";
images[11] = new Image();
images[11].src = "azbuka/Й.gif";
images[12] = new Image();
images[12].src = "azbuka/К.gif";
images[13] = new Image();
images[13].src = "azbuka/Л.gif";
images[14] = new Image();
images[14].src = "azbuka/М.gif";
images[15] = new Image();
images[15].src = "azbuka/Н.gif";
images[16] = new Image();
images[16].src = "azbuka/О.jpg";
images[17] = new Image();
images[17].src = "azbuka/П.jpg";
images[18] = new Image();
images[18].src = "azbuka/Р.jpg";
images[19] = new Image();
images[19].src = "azbuka/С.jpg";
images[20] = new Image();
images[20].src = "azbuka/Т.jpg";
images[21] = new Image();
images[21].src = "azbuka/У.jpg";
images[22] = new Image();
images[22].src = "azbuka/Ф.jpg";
images[23] = new Image();
images[23].src = "azbuka/Х.jpg";
images[24] = new Image();
images[24].src = "azbuka/Ц.jpg";
images[25] = new Image();
images[25].src = "azbuka/Ч.jpg";
images[26] = new Image();
images[26].src = "azbuka/Ш.jpg";
images[27] = new Image();
images[27].src = "azbuka/Щ.jpg";
images[28] = new Image();
images[28].src = "azbuka/Ы.jpg";
images[29] = new Image();
images[29].src = "azbuka/Э.jpg";
images[30] = new Image();
images[30].src = "azbuka/Ю.jpg";
images[31] = new Image();
images[31].src = "azbuka/Я.jpg";


function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
// End -->
</script>

И в <body>


<OnLoad="swapPic()">
<center>
<a onClick="swapPic();"><img name="randimg" src="azbuka/А.gif" width="680" height="450"></a><br>

</center>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0


var count = 0;
function swapPic() {
if (count <= images.length) {
count++;
document.randimg.src = images[count].src;
}
else {
count = 0;
document.randimg.src = images[count].src;
}
}

Работоспособность не проверял, так что не исключено, что не сработает)

Почему бы не использовать jquery? будет же гораздо проще

Edited by Mayhem
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy