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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:44:30+00:00 2026-06-08T10:44:30+00:00

Morning folks. Have an issue with a simple jQuery gallery i’m making. It lets

  • 0

Morning folks. Have an issue with a simple jQuery gallery i’m making. It lets the user cycle through a collection of images via some buttons and at the same time, rotates through these images on a timer. My problem is that the user is able to click the button multiple times which queues up the fade in animation and repeats it over and over, e.g. user clicks button 5 times > same image fades in/out 5 times > gallery moves to next image.

I’ve tried using:

$('#homeGalleryImage li a').unbind('click');

After the click event is fired and then rebinding:

$('#homeGalleryImage li a').bind('click');

After it’s done but this simply removes the click event after pressing a button once and never rebinds to it?

I’ve also tried disabling the button via:

$('#homeGalleryImage li a').attr('disabled', true);

To no avail… ?

There is a secondary issue where if you manage to click a button while the image is in a transition, the next image appears ‘faded’ as if the opacity has been lowered? Very strange… Here is the code for button clicks:

var i = 1;
var timerVal = 3000;
$(function () {
    $("#homeGalleryControls li a").click(function () {
        var image = $(this).data('image');
        $('#galleryImage').fadeOut(0, function () {
            $('#galleryImage').attr("src", image);
        });
        $('#galleryImage').fadeIn('slow');
        $('.galleryButton').attr("src", "/Content/Images/Design/btn_default.gif");
        $(this).find('img').attr("src", "/Content/Images/Design/btn_checked.gif");
        i = $(this).data('index') + 1;
        if (i == 4) {
            i = 0;
        }
        timerVal = 0;
    });
});

Here is the code that cycles through the images on a timer:

//Cycle through gallery images on a timer
window.setInterval(swapImage, timerVal);
function swapImage() {
    $('#galleryImage').fadeOut(0, function () {
        var imgArray = ["/Content/Images/Design/gallery placeholder.jpg", "/Content/Images/Design/1.jpg", "/Content/Images/Design/2.jpg", "/Content/Images/Design/3.jpg"];
        var image = imgArray[i];
        i++;

        if (i == 4) {
            i = 0;
        }

        $('#galleryImage').attr("src", image);
        $('#galleryImage').fadeIn('slow');
    });
    var currentButton = $('#homeGalleryControls li a img').get(i - 1);
    $('.galleryButton').attr("src", "/Content/Images/Design/btn_default.gif");
    $(currentButton).attr("src", "/Content/Images/Design/btn_checked.gif");
}

I realise it might be a better idea to use a plugin but I’m very new to jQuery and I’d like to learn something rather than using some ready made code.

Any help at all, is much appreciated.

Thankyou

  • 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-08T10:44:32+00:00Added an answer on June 8, 2026 at 10:44 am

    You could always try adding something to the element to cancel the click event?

    For example

    $(".element").click(function(e) {
    
        if ( $(this).hasClass("unclickable") ) {
            e.preventDefault();
        } else {
    
            $(this).addClass("unclickable");
            //Your code continues here
            //Remember to remove the unclickable class when you want it to run again.
    
        }
    
    }):
    

    In your case you could try adding a check on the click.

    $('#homeGalleryImage li a').attr('data-disabled', "disabled");
    

    Then inside your click event

    if ( $(this).attr("data-disabled" == "disabled") {
      e.preventDefault();
    } else {
      //Ready to go here
    } 
    

    Edit

    Here is a working example showing the element becoming unclickable. http://jsfiddle.net/FmyFS/2/

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

Sidebar

Related Questions

Morning folks. I have an interactive gallery in mind, whereby a user hovers over
Morning, simple stupid question. I have found post with similar issues but after reading
Morning folks. Novice Rich here once again requesting assistance. I have just started dabbling
Morning all...thicky, newbie Rich here! I have a very simple set up, three different
Morning all, I have a simple question that I could do with some help
Good morning folks, I'm just that beginner in json, I have a formated data
Morning folks, I have a temporary table with 135,000 rows and 24 columns, of
Morning All, I have been writing an ever so simple IRC client in visual
Morning all, I have a list of images like so: <ul id=preload style=display:none;> <li><img
Good morning, folks. I have a question here. I have three select. Brings first

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.