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

  • Home
  • SEARCH
  • 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 8363027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:04:51+00:00 2026-06-09T12:04:51+00:00

I have a function that is advancing scrolling images on a webpage. It can

  • 0

I have a function that is advancing scrolling images on a webpage. It can be seen here:

http://leadgenixhosting.com/~intmed/

The right arrow is what you click to advance the images. I have this problem where I have used .unbind() so that the arrow is unclickable until the images have finished with .animate() so that they don’t get out of sync. But I’m not exactly sure how to use .bind() to make the arrow clickable again.

This is what the function currently looks like:

$('#in-right').click(
        function(){
            $('#in-right').unbind('click');
            imageSwitch();
            $('#in-right').bind('click');
        }
);

I’m obviously implementing bind incorrectly. How can I implement it right?

Here is my imageSwitch() function:

function imageSwitch(){

        current++;
        current_image++;
        previous_image++;
        next++;
        two_prev++

        if(two_prev >= divs.length){
            two_prev = 0;   
        }

        if(current >= gallery_images.length){
            current = 0;    
        }

        if(previous_image >= divs.length){
            previous_image = 0; 
        }

        if(current_image >= divs.length){
            current_image = 0;
        }

        if(next >= divs.length){
            next = 0;
        }   

        $('#'+divs[current_image]+'').animate({left:'-=1020px'},{queue:false,duration:1000})
        $('#'+divs[current_image]+'').css('background-image','url('+gallery_images[current]+')');

        $('#'+divs[previous_image]+'').animate({left:'-=1020px'},{queue:false,duration:1000});

        $('#'+divs[next]+'').animate({left: '+=1020px', top: '-=10000px'}, 1000);

        $('#'+divs[two_prev]+'').animate({left: '+=1020px', top: '+=10000px'}, 1000);
    }
  • 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-06-09T12:04:53+00:00Added an answer on June 9, 2026 at 12:04 pm

    .bind requires you pass it a function as the 2nd parameter.

    function clickFunc(){  // Give the event function a name
        $('#in-right').unbind('click');
        imageSwitch();
        $('#in-right').click(clickFunc);  // .click is shorthand for `.bind('click',`
    }
    $('#in-right').click(clickFunc);
    

    EDIT: You should make your imageSwich function take a callback, so it can re-bind the function once it’s done animating.

    function imageSwitch(callback){
        // code...
    }
    
    function clickFunc(){  // Give the event function a name
        $('#in-right').unbind('click');
        imageSwitch(function(){
            $('#in-right').click(clickFunc);
        });
    }
    $('#in-right').click(clickFunc);
    

    As for making sure the callback runs once all the animations are done, we can use jQuery’s deferreds.

    Basically, you want to save the objects returned from .animate into varibles. Then use $.when, and .then to run the callback at the correct time.

    (This is untested, BTW)

    function imageSwitch(callback) {
        var animations = [];
    
        current++;
        current_image++;
        previous_image++;
        next++;
        two_prev++
    
        if (two_prev >= divs.length) {
            two_prev = 0;
        }
    
        if (current >= gallery_images.length) {
            current = 0;
        }
    
        if (previous_image >= divs.length) {
            previous_image = 0;
        }
    
        if (current_image >= divs.length) {
            current_image = 0;
        }
    
        if (next >= divs.length) {
            next = 0;
        }
    
        animations.push($('#' + divs[current_image] + '').animate({
            left: '-=1020px'
        }, {
            queue: false,
            duration: 1000
        }));
    
        $('#' + divs[current_image] + '').css('background-image', 'url(' + gallery_images[current] + ')');
    
        animations.push($('#' + divs[previous_image] + '').animate({
            left: '-=1020px'
        }, {
            queue: false,
            duration: 1000
        }));
    
        animations.push($('#' + divs[next] + '').animate({
            left: '+=1020px',
            top: '-=10000px'
        }, 1000));
    
        animations.push($('#' + divs[two_prev] + '').animate({
            left: '+=1020px',
            top: '+=10000px'
        }, 1000));
    
        if (typeof callback === 'function') {
            // Apply is used here because `$.when` expects to passed multiple parameters
            $.when.apply($,animations).then(callback);
        }
    }
    

    Deferred and animations demo: http://jsfiddle.net/M58KK/

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

Sidebar

Related Questions

I have a function that inserts data into a SQLite database. I can manually
I have a function that takes a callback argument. This can be either a
Inside my Controller i have function that runs after user clicks on item, which
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have a function that returns two values in a list. Both values need
I have a function that takes an input string and then runs the string
I have a function that does a long task and I want to update
I have a function that counts the amount of visits a page has, and

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.