Jump to content

jQuery Click Handler Problem


Recommended Posts

I have a click handler that is causing some problem. I am using hammer.js for a slider. 

 

This is the link http://ingrub.com/iphone/

 

When you hit the last slide the text of next changes to let's grub, but the problem is that if you swipe back to an earlier screen and you try to go next it automatically goes to the link instead of going to the next slide these are some of the functions that i am using 

this.showPane = function(index, animate) {
            // between the bounds
            index = Math.max(0, Math.min(index, pane_count-1));
            current_pane = index;

            var offset = -((100/pane_count)*current_pane);
            setContainerOffset(offset, animate);
            
            

            if(current_pane == 2){
                $(".next2").text("Let's Grub");
                $(".navigation2").addClass('linkMe');

                
            } else {
                $(".next2").text("Next");
                $(".navigation2").removeClass('linkMe');
            }

    
        };
$( ".next2" ).click(function() {
        carousel.next();

       $('.linkMe').click(function() {
            window.location = "discover.html";
        });
       return false;
    });

I am not sure what to do to fix this bug. 

Link to comment
Share on other sites

Removing the linkMe class will not remove the click handler you install on the element. What you should do is install the click handler on the element regardless of whether the linkMe class is present or not, but then have the handler only do something if the class is present:

//Add a click handler to the navigation2 element
$('.navigation2').click(function(e){
   //If the element also has the linkMe class
   if ($(e.currentTarget).is('.linkMe')){
      //Do the redirect
      window.location.href = 'discover.html';
   }
});
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.