简体   繁体   English

如何使用纯JavaScript制作简单的图库

[英]How to make simple image gallery using pure javascript

I am new to javaScript and i tried to make a photo gallery for practice purpose.I don't know about jQuery so i dont want to use it right now Most of the stuff on Internet is using JQUERY. 我是javaScript的新手,我试图为实践目的制作一个照片库。我不知道jQuery所以我现在不想使用它大多数互联网上的东西都在使用JQUERY。

I want to slide the image, using Next image button but 我想使用下一个图像按钮滑动图像,但是

  1. when i click the first img tag ,it works fine. 当我点击第一个img标签时,它工作正常。
  2. when i click on second input tag same image comes again . 当我点击第二个输入标签时,同一图像再次出现。

Whats the Difference between these two tags. 什么是这两个标签之间的差异。 Function is being called.I have checked using alert . 正在调用函数。我已使用alert进行了检查。 and it is uncaught reference error 它是未被捕获的参考错误

I Searched a lot after a lot of alterations my code is like this Script: 经过大量修改后我搜索了很多,我的代码就像这个脚本:

 <script type="text/javascript">
    var k = 0;
    var imageName = new Array(6);
    imageName[1] = "1.jpg";
    imageName[2] = "2.jpg";
    imageName[3] = "3.jpg";
    imageName[4] = "4.jpg";
    imageName[5] = "5.jpg";
    imageName[6] = "6.jpg";

      function NextImage(){

        if (k == 6) {
            k = 0;
        }
        k++;
        document.getElementById("imagebox").src =imageName[k];

    }
</script>

html: HTML:

<form id="form1" runat="server">
<div>
<img id="picbox" src="1.jpg" height="500" width="500" alt="iMAGE NOT FOUND" />
<img src=green-next-button.jpg onclick="javascript:NextImage()" />
<input type="image" onclick="NextImage()" src=green-next-button.jpg />

</div>

Kindly Trace the problem in code .Thanks in Advance. 请在代码中跟踪问题。谢谢提前。 Debugging is Disabled due to some Web.config file and it is also recommended . 由于某些Web.config文件,调试已禁用,因此也建议使用。 Kindly help me how to Debug Html tags. 请帮我如何调试Html标签。

Javascript at this level is extremely easy to debug using a client-side debugger. 使用客户端调试器可以非常轻松地调试此级别的Javascript。 This kind of function is something everyone should learn to use as part of learning Javascript. 这种功能是每个人都应该学习使用的东西,作为学习Javascript的一部分。

For firefox, here is the addon you can download to your browser to add a debugger: https://addons.mozilla.org/en-US/firefox/addon/firebug/ 对于firefox,这里是你可以下载到你的浏览器添加调试器的插件: https//addons.mozilla.org/en-US/firefox/addon/firebug/

For Chrome the Chrome developer tools are a good place to start, click CTRL+SHIFT+J to get the javascript console. 对于Chrome,Chrome开发者工具是一个很好的起点,点击CTRL + SHIFT + J即可获得javascript控制台。 Here is an explanation for how Javascript debugging in Chrome is done: 以下是有关如何在Chrome中调试Javascript的说明:

https://developers.google.com/chrome-developer-tools/docs/javascript-debugging https://developers.google.com/chrome-developer-tools/docs/javascript-debugging

Here is a tutorial that may help to teach you how to build one yourself. 这是一个教程,可能有助于教你如何自己构建一个。

http://jjames.info/Tutorials/Tutorial1/tutorial1.php . http://jjames.info/Tutorials/Tutorial1/tutorial1.php

On this page is a simple tutorial teaching how to create a Javascript image gallery that you may be able to use or may be able to help you understand how to create one yourself. 在这个页面上有一个简单的教程,教你如何创建一个你可以使用的Javascript图库,或者可以帮助你了解如何自己创建一个。

Since you have no experience I would take the easy way and just find a library. 由于你没有经验,我会采取简单的方法,只是找到一个图书馆。 Use google and you find multiple. 使用谷歌,你会发现多个。 If you are going to start from scratch it will take you a lot of time. 如果你要从头开始,那将花费你很多时间。

Still want to continue? 还想继续? Then also learn debugging your code. 然后还学习调试代码。 place a console.log(imagename[k]) on the place where you alter the image tag. 在您更改图像标记的位置放置console.log(imagename [k])。 If you see different image names then the problem lies in your images itself. 如果您看到不同的图像名称,则问题出在图像本身。

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

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