Question

Hi.
I have a continue and stop function.
When i call the stop function by clicking in one of the blue boxes it calls the continue function 1 ms later.

My problem is when i click the 'Document' it should call the stop function again but it does not do that, here is a fiddle for a closer look.

JsFiddle

PS: in the javascript code you have to scroll all the way down becouse i could not include the Jquery plugin.

I marked my problem with this comment where my coding starts:

//############ here starts my part ####################
Was it helpful?

Solution

As indicated in the comments, don't rebind your event each and every time stop() is called. Let's move that binding out, and we're also going to use stopPropgation() so that the click event won't bubble up to the document, which will trigger the plugin to start its mojo again:

function stop(){     
    $("#webticker").trigger('click'); //This method doesn't provide anything, except perhaps making code a bit more readable
}

$("#webticker").click(function(event){
        event.stopPropagation(); //If we don't stop propagation, the click event will bubble up to the document, which will start the ticker again
        $("#webticker").webTicker('stop');

          if($(event.target).is('#img1')) {
            $('#log').html(event.target.id + ' was clicked.');
            timer = setTimeout(contin, 1);
        } else if($(event.target).is('#img2')){
            $('#log').html(event.target.id + ' was clicked.');
            timer = setTimeout(contin, 1);
        } else if($(event.target).is('#img3')){
            $('#log').html(event.target.id + ' was clicked.');
            timer = setTimeout(contin, 1);
        } else if($(event.target).is('#img4')){
            $('#log').html(event.target.id + ' was clicked.');
            timer = setTimeout(contin, 1);
        } else if($(event.target).is('#img5')){
            $('#log').html(event.target.id + ' was clicked.');
            timer = setTimeout(contin, 1);
        }
  });

JSFiddle: http://jsfiddle.net/rLyyR/6/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top