Next and Previous buttons in jquery image gallery
I want to code the next and previous buttons for my jquery image gallery. When i click on next button, it shows me the first image of the gallery and then it stops working for any other image. Can someone help me what i am doung wrong in my code? Please help? Below is jquery.
- <script type="text/javascript">
- jQuery(document).ready(function () {
- jQuery('.item').click(function () {
- // Getting "src" attribute of the image that was clicked.
- var path = jQuery(this).find('img').attr('src');
- document.getElementById('tempVal').value = path;
- // Setting "src" attribute of the big image.
- jQuery('#big img').attr('src', path);
- jQuery('#bcktopainting').attr('style', 'display:normal;');
- });
- jQuery('#bcktopainting').click(function () {
- jQuery('#big img').attr('src', '');
- jQuery('#bcktopainting').attr('style', 'display:none;')
- });
- jQuery('.next').click(function () {
- var currentItem = document.getElementById('tempVal').value;
- currentItem.next();
- var nextPath = jQuery('ul').find('li').find('img').attr('src', currentItem).next();
- jQuery('#big img').attr('src', nextPath);
- });
- });
Below is HTML:
- <body>
- <input type="hidden" id="tempVal" name="tempValues" value="" style="display: none;" />
- <main class="page payment-page">
- <section class="payment-form dark">
- <div class="container">
- <div class="block-heading">
- <a href="Index.aspx">
- <img src="assets/images/kmac_logo.jpg" />
- </a>
- <center>
- <nav class="navbar navbar-default navigation-clean-button" style="width: 350px;">
- <div class="navbar-header">
- <button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span>
- <span class="icon-bar"></span><span class="icon-bar"></span></button>
- </div>
- <div class="collapse navbar-collapse" id="navcol-1">
- <ul class="nav navbar-nav">
- <li role="presentation"><a href="Painting.aspx">Painting</a></li>
- <li role="presentation"><a href="Painting2.aspx">Painting 2</a></li>
- <li role="presentation"><a href="Contact.aspx">Contact</a></li>
- </ul>
- </div>
- </nav>
- </center>
- </div>
- <form runat="server" id="big">
- <img src="" />
- <div class="card-details">
- <p id="bcktopainting" style="display: none; float: left;">Back To Painting</p>
- <p style="" id="prev" onclick="showPrev();">Previous</p>
- /<p style="" id="next" class="next">Next</p>
- </div>
- </form>
- <section class="gallery-block grid-gallery">
- <div class="container">
- <ul class="row" id="row" runat="server">
- </ul>
- </div>
- </section>
- </div>
- </section>
- </main>
- </body>
And Below is my ASP.NET code for fetching the images.
- public partial class Painting : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- imageRetriever();
- }
- private void imageRetriever()
- {
- StringBuilder table = new StringBuilder();
- foreach (string strFileName in Directory.GetFiles(Server.MapPath("PaintingPagePictures/")))
- {
- FileInfo fileInfo = new FileInfo(strFileName);
- table.Append("<li class=\"col-md-6 col-lg-4 item\">");
- table.Append("<img class=\"img - fluid image scale - on - hover\" src=\"PaintingPagePictures/" + fileInfo.Name + "\" />");
- table.Append("</li>");
- }
- row.InnerHtml = table.ToString();
- }
- }