Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an event that triggers a second event

I'm trying to create a jQuery event that triggers a second event. The first event is clicking on the emoji id which refers to an image. The second is a mousemove event which moves the image around the page. The third event stops this event when the mouse click happens again anywhere in the body of the page and places the image at that absolute position. I was able to get the second and the third events to work but I can't get the first event to work with the second. Here is what I have so far for my jQuery:

var mouseTracker  = function(event) {
console.log(event.pageX, event.pageY, !!event.which)
$('#emoji').css('top', event.pageY);
$('#emoji').css('bottom', event.pageY);
$('#emoji').css('left', event.pageX);
$('#emoji').css('right', event.pageX);
}

var begin = function() {
$('body').on('mousemove', mouseTracker);
$('body').css('cursor', 'none');
}

var stop = function() {
$('body').off('mousemove', mouseTracker);
$('#emoji').css('postion', 'absolute')
$('body').css('cursor', 'default');
}

$('#emoji').on('click', begin);
$('body').on('click', stop);`
like image 557
ultra_rn Avatar asked Oct 15 '15 17:10

ultra_rn


People also ask

What is an example of a triggering event?

Triggering events include job loss, retirement, or death, and are typical for many types of contracts. These triggers help to prevent, or ensure, that in the case of a catastrophic change, the terms of an original contract may also change. Life insurance policies may include a triggering event based on the insured age.

What are trigger events in insurance?

Examples of trigger events could be instances where an insurer's internal risk assessment methodology has substantially changed; or where the insurer becomes aware that it lacks sufficient information about the customer concerned.

Which are types of events in trigger?

There are two types of trigger events: database trigger events and page trigger events.


1 Answers

Initialize the event from within the first event call.

$('#emoji').on('click', function() {
    begin();
    $('body').on('click', stop);
});
like image 175
Sterling Archer Avatar answered Oct 18 '22 17:10

Sterling Archer