My first gallery app
My first gallery app
Hi there
I have been experimenting with jQuery for the first time this past week. I thought that I understood it well enough, but now something isn't clicking. I tried to write a simple image gallery but it just does not seem to do what I expected it to.
Here is my code:
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Untitled Document</title>
- <script type="text/javascript" src="jQuery.js"></script>
- <style>
- ul li{
- display:none;
- list-style-type:none;
- }
- </style>
- <script type="text/javascript">
- $(function() {
- var i=0;
- $('#imageList li:eq(0)').slideDown('fast');
- $('#next').click(function (){
- $('#imageList li:eq(i)').slideUp('fast');
- i++;
- $('#imageList li:eq(i)').slideDown('fast');
- });
- $('#prev').click(function (){
- $('#imageList li:eq(i)').slideUp('fast');
- i--;
- $('#imageList li:eq(i)').slideDown('fast');
- });
- });
- </script>
- </head>
- <body>
- <ul id="imageList">
- <li><img src="1.jpg" /></li>
- <li><img src="2.jpg" /></li>
- <li><img src="3.jpg" /></li>
- <li><img src="4.jpg" /></li>
- </ul>
- <a href="#" id="prev">Prev</a>
- <a href="#" id="next">Next</a>
- </body>
- </html>
The problem seems to be that it does not accept the variable 'i' as a parameter for li:eq() on lines 17, 19, 22 and 24. I've output i's value to the console and it looks fine. If I replace it with numerical values it works fine, but then I can't change which image I'm showing and hiding.
Does anyone have any suggestions why this is not working?