One of the processes that I think you can do to get a little bit more elaborate in jQuery is to handle timers. I always forget to look it up, so here’s a note
Sample Code for Timer Handling
inertval = 5000; //How many seconds to process (in this case, 5 seconds)
//Timer start function
function startTimer(){
Execute the syori function every //second of inertval. The information is put into the timer variable.
timer = setInterval(syori, inertval);
}
//Timer stop function
function stopTimer(){
Stop the //timer variable.
clearInterval(timer);
}
//Start the timer.
startTimer();
// Stop the timer (here we are using mouse over and out on the element as an example)
$('.element').on({
'mouseenter': function(){ //when the mouse is over, the
stopTimer(); //stop
},
'mouseleave': function(){ //when you mouse out
startTimer(); //Move it again
}
});
function syori(){
// Describe here the process per second of inertval
}
Supplement.
- To start the timer, you can set a variable (in this case, timer) to setInterval Insert command.
- When we stop, we’ll specify a variable that we’ve decided on with a clearInterval.
- Because the code for setInterval tends to be long, it is possible to use If you write it separately, it will be easier to look back at later.
- If you are using multiple timers, you can use startTimer It may be more useful to rework () and stopTimer().