简体   繁体   English

JavaScript图像滑块/目录

[英]JavaScript image slider/catalog

So i'm trying to make a simple image "catalog" where i can cycle through some images. 因此,我正在尝试制作一个简单的图像“目录”,以便在其中循环显示某些图像。 Here's the code: http://pastebin.com/raw/NDh4VBtz Im facing two problems at this moment: 这是代码: http : //pastebin.com/raw/NDh4VBtz目前,我面临两个问题:

    1. How to make the buttons which i'm using to move forward after the 1st press. 第一次按下后如何使我正在使用的按钮前进。 Example: I have 3 images (IMG1, IMG2, IMG3). 示例:我有3张图片(IMG1,IMG2,IMG3)。 I want to use them as follows. 我想如下使用它们。 I press button "Next image": IMG1 -> IMG2. 我按下按钮“下一张图片”:IMG1-> IMG2。 I press said button again: IMG2 -> IMG3. 我再次按下按钮:IMG2-> IMG3。 If i press "Previous image": IMG3 -> IMG2. 如果我按“上一张图像”:IMG3-> IMG2。 At this point i've made it so it would work the first time when i press "Next image" or "Previous image". 在这一点上,我已经做到了,因此当我按下“下一张图像”或“上一张图像”时,它将可以首次使用。
    1. How to store image position so that when i call the function again, it wouldn't lose the value. 如何存储图像位置,以便当我再次调用该函数时,它不会丢失该值。 I'm using onclick event - onclick="imagesS('Image', 'Text', Images, -1)". 我正在使用onclick事件-onclick =“ imagesS('Image','Text',Images,-1)”。 Image = imageID, Text = textID, Images = image array, -1 = direction. 图片= imageID,文字= textID,图片=图片数组,-1 =方向。

JavaScript part of the file: 文件的JavaScript部分:

 <script type="text/javascript">
     var Images = 
        new Array("first.jpg", "second.jpg", "third.jpg", 0)

     function imagesS(ImageId, TxtId, ImageArr, Direction) {
            IndPos = 0;
            if (Direction == "+1"){
                IndPos += 1;
                if (ImageArr.length == IndPos) {
                    alert("Last photo!");
                } else {
                    document.getElementById(ImageId).src= ImageArr[IndPos];
                    document.getElementById(TxtId).innerHTML = "Text: <i>" + ImageArr[IndPos] + "</i>";
                }
            }   else if (Direction == "-1"){
                    IndPos -= 1;
                    if (IndPos == "0" || IndPos == "-1"){
                        alert("Can't do that!");
                    }   else {
                    document.getElementById(ImageId).src= ImageArr[IndPos];
                    document.getElementById(TxtId).innerHTML = "Text: <i>" + ImageArr[IndPos] + "</i>";
                    }
                }

     } 

也许这样的事情对您有用: imageCatalog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM