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 1105495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:38:31+00:00 2026-05-17T01:38:31+00:00

Working on an image gallery, but it keeps crashing on me (you control it

  • 0

Working on an image gallery, but it keeps crashing on me (you control it by clicking on ‘left’ and ‘right’) if i click on the images more than 10 times:

http://korrektur.adnuvo.com/hejven/index_test2.html

Here’s the code:

$(document).ready(function(){

/*''''''''''' WORKING COPY !!!!! V2 '''''''''''*/
var gal_prev = null;
var gal_next = null;

var click_img = function() {
    console.profile();

    $(this).unbind();

    if($(this).attr('class') == 'gal_right') {
        /* IF RIGHT */
        /*$('#test').append('Im right. ');*/
        get_pos($(this));

        $(this).siblings('.gal_left').removeClass().addClass('gal_img');
        $(this).siblings('.gal_right').removeClass().addClass('gal_img');
        $(this).removeClass().addClass('gal_active');

        $(gal_prev).removeClass().addClass('gal_left');
        $(gal_prev).bind('click',click_img);

        $(gal_next).removeClass().addClass('gal_right');
        $(gal_next).bind('click',click_img);
    } else {
        /* IF LEFT */
        /*$('#test').append('Im left. ');*/

        get_pos($(this));

        /*$(this).parent().children().removeClass().addClass('gal_img');*/
        $(this).siblings('.gal_left').removeClass().addClass('gal_img');
        $(this).siblings('.gal_right').removeClass().addClass('gal_img');
        $(this).removeClass().addClass('gal_active');

        $(gal_prev).removeClass().addClass('gal_left');
        $(gal_prev).bind('click',click_img);

        $(gal_next).removeClass().addClass('gal_right');
        $(gal_next).bind('click',click_img);
    }

    console.profileEnd();
}

/* BIND ACTIONS TO IMAGES */
$('#img2').bind('click',click_img);
$('#img5').bind('click',click_img);

/* GET POSITION */
var get_pos = function(gal_clicked) {
    if(($(gal_clicked).next().length != 0) && ($(gal_clicked).prev().length != 0)) {
        /*$('#test').append('Im in the middle somewhere. ');*/
        gal_prev = $(gal_clicked).prev();
        gal_next = $(gal_clicked).next();
    } else if($(gal_clicked).prev().length != 0) {
        /*$('#test').append('Im last. ');*/
        gal_prev = $(gal_clicked).prev();
        gal_next = $(gal_clicked).parent().find('div:first');
    } else {
        /*$('#test').append('Im first. ');*/
        gal_prev = $(gal_clicked).parent().find('div:last');
        gal_next = $(gal_clicked).next();
    }
} });

Can anyone help me out. I’m not a master at jquery, so all tips and comments are more than welcome 🙂

  • 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-17T01:38:32+00:00Added an answer on May 17, 2026 at 1:38 am

    You only unbind the the click event from the currently clicked element (either left or right, but not from both buttons), and then reassign new events..

    A simple solution to your problem, thus, would be to change $(this).unbind(); to $(this).unbind().siblings().unbind()

    You could just assign the click event to all divs and sniff the action to perform like you do now from the class the element has (without any unbinding / rebinding) ..

    Additionally you do not have to wrap jquery object with the $ again ..

    All those changes in your code would yield

    var gal_prev = null;
    var gal_next = null;
    
    var click_img = function() {
        console.profile();
        if($(this).attr('class') == 'gal_right') {
            /* IF RIGHT */
            /*$('#test').append('Im right. ');*/
            get_pos($(this));
    
            $(this).siblings('.gal_left').removeClass().addClass('gal_img');
            $(this).siblings('.gal_right').removeClass().addClass('gal_img');
            $(this).removeClass().addClass('gal_active');
    
            gal_prev.removeClass().addClass('gal_left');
    
            gal_next.removeClass().addClass('gal_right');
        } else if($(this).attr('class') == 'gal_left'){
            /* IF LEFT */
            /*$('#test').append('Im left. ');*/
    
            get_pos($(this));
    
            /*$(this).parent().children().removeClass().addClass('gal_img');*/
            $(this).siblings('.gal_left').removeClass().addClass('gal_img');
            $(this).siblings('.gal_right').removeClass().addClass('gal_img');
            $(this).removeClass().addClass('gal_active');
    
            gal_prev.removeClass().addClass('gal_left');
    
            gal_next.removeClass().addClass('gal_right');
        }
        console.profileEnd();
    }
    
    /* BIND ACTIONS TO IMAGES */
    $('.gal_container div').bind('click',click_img);
    
    /* GET POSITION */
    var get_pos = function(gal_clicked) {
        if((gal_clicked.next().length != 0) && (gal_clicked.prev().length != 0)) {
            /*$('#test').append('Im in the middle somewhere. ');*/
            gal_prev = gal_clicked.prev();
            gal_next = gal_clicked.next();
        } else if(gal_clicked.prev().length != 0) {
            /*$('#test').append('Im last. ');*/
            gal_prev = gal_clicked.prev();
            gal_next = gal_clicked.parent().find('div:first');
        } else {
            /*$('#test').append('Im first. ');*/
            gal_prev = gal_clicked.parent().find('div:last');
            gal_next = gal_clicked.next();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an image gallery, where the user can upload images. When an
I'm working on an image gallery, where the user can upload images. The uploaded
I'm currently working on a web site that will show kind a image gallery
I'm working on a django app for a site that requires an image gallery.
I am working on creating an image gallery which has thumbnails in different sizes.
in the image gallery i'm working on, I want a horizontal scroll (ie. the
I'm working on a thumbnail page for an image gallery. Thumbnail previews are done
I am working on an image gallery, and on the browse image module, I
I'm using jQuery to control an image gallery that will display any of several
I have gallery in my project. I save images on the hard drive but

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.