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
https://forums.phpfreaks.com/topic/288829-jquery-click-handler-problem/
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';
   }
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.