Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:42:21+00:00 2026-05-25T01:42:21+00:00

I got this code from Jquery in Action: $.fn.photoslide = function(options) { var settings

  • 0

I got this code from Jquery in Action:

$.fn.photoslide = function(options) {
            var settings = $.extend({
                photoElement:'img.photoslidePhoto',
                transformer:function(name) {
                    return name.replace(/thumbnail/,'photo');
                },
                nextControl:null,
                previousControl:null,
                firstControl:null,
                lastControl:null,
                playControl:null,
                delay:3000
            },options||{});
$(settings.previousControl)
        .click(function() {
             showPhoto((settings.thumbnails$.length + settings.current - 1) 
                       % settings.thumbnails$.length);
                }); //Why not just use settings.current - 1??

the code is meant to be used with a slider. The slider has a button that displays the previous photo.
This is the code for the showPhoto() function:

function showPhoto(index) {
                $(settings.photoElement).attr('src',settings.transformer(settings.thumbnails$[index].src));
                settings.current = index;
            };

            settings.thumbnail$
                .each(function(n) {
                $(this).data('photo-index',n);
                })
                .click(function() {
                    showPhoto($(this).data('photo-index'));
                }); 

My question is, why can’t the index argument for showPhoto() in the click event for $(settings.previousControl) be defined simply as settings.current - 1?

I know this is a long post, but I would appreciate it very much if someone could help me understand this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:42:21+00:00Added an answer on May 25, 2026 at 1:42 am

    settings.thumbnails$.length is added to avoid negative indexes.

    If it was not added and settings.current is 0, the result would be -1. Important to know is that applying the modulus in JavaScript does not make the number positive (unlike in other languages like Python):

    > -1 % 5
      -1
    

    It would stay -1 which eventually would result in an error if you try to access an array with it.

    Adding settings.thumbnails$.length guarantees the number to be positive but does not change the result (as it is zero in the context of the modulus operator).

    In case you wondered what the modulus operator [Wikipedia] is for: I assume this is used to show the photos in a loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code: $('.save').submit(function(e){ var formElement = $(this); var data =
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what
I got this code from someone, it's almost perfect to create a dynamic breadcrumb,
I got this code from someone and it works very well, I just want
I got this javascript code from off the internet. It's a script that changes
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I got this piece of Assembly code extracted from some piece of software, but
How can I fetch images from a server? I've got this bit of code
I've got this code: <html> <head> <link type=text/css href=css/blitzer/jquery-ui-1.7.2.custom.css rel=stylesheet /> <script type=text/javascript src=js/jquery-1.3.2.min.js></script>
I found this code on here from this post: jQuery Accordion: links don't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.