Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Pause interval button javascript

var i = 0;
this.setInterval(function() {
  if(!$('#counter').hasClass('pauseInterval')) { //only run if it hasn't got this class 'pauseInterval'
    console.log('Counting...');
    $('#counter').html(i++); //just for explaining and showing
  } else {
    console.log('Stopped counting');
  }
}, 500);

/* In this example, I'm adding a class on mouseover and remove it again on mouseleave. You can of course do pretty much whatever you like */
$('#counter').hover(function() { //mouse enter
    $(this).addClass('pauseInterval');
  },function() { //mouse leave
    $(this).removeClass('pauseInterval');
  }
);

/* Other example */
$('#pauseInterval').click(function() {
  $('#counter').toggleClass('pauseInterval');
});
Comment

Pause interval button javascript

body {
  background-color: #eee;
  font-family: Calibri, Arial, sans-serif;
}
#counter {
  width: 50%;
  background: #ddd;
  border: 2px solid #009afd;
  border-radius: 5px;
  padding: 5px;
  text-align: center;
  transition: .3s;
  margin: 0 auto;
}
#counter.pauseInterval {
  border-color: red;  
}
Comment

Pause interval button javascript

<!-- you'll need jQuery for this. If you really want a vanilla version, ask -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<p id="counter"> </p>
<button id="pauseInterval">Pause</button></p>
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: Error: ENOENT: no such file or directory, scandir 
Javascript :: e.addEventListener("input", function(){ e.value?n.innerText="Nama: "+e.value:n.innerText=""; }); 
Javascript :: how to use cookiestore javascript console 
Javascript :: type.js 
Javascript :: start withnreact 
Javascript :: react history push search params 
Javascript :: enum string json 
Javascript :: how to add types of a chance mixin 
Javascript :: native module reactnativepushnotification tried to override rnpushnotification 
Javascript :: node_modules/mongodb/lib/json.js:10 catch { } // eslint-disable-line 
Javascript :: how to stop component to render multiple time 
Javascript :: random number from 1 to 10000 js 
Javascript :: react native elements datepicker 
Javascript :: get ordinal number 
Javascript :: jest check the link of a button 
Javascript :: sequelize read from moel 
Javascript :: how to write text with javascript 
Javascript :: auto refresh database in outsystems reactive 
Javascript :: react native icons in one file 
Javascript :: show hide pseudo element jquery 
Javascript :: javascript escape comma in csv 
Javascript :: add content in textarea by clicking on button 
Javascript :: destructring global state at one place 
Javascript :: The console Module 
Javascript :: how to show conditional show on select field 
Javascript :: js check if field in database is true or false 
Javascript :: vite esbuild configuration 
Javascript :: flow parsing package.json and showing error 
Javascript :: how to hide all tabs in windows 10 
Javascript :: errorhandler npm 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =