I want to call a Javascript function after clicking a button, make it loop every 100 milliseconds for 1,5 seconds and then pause it.
The idea is that I want to make this accordion slider able to show scrollable content using this custom jQuery scrollbar(I have no idea of any other better custom cross-browser scrollbar).
The scrollbar must be reconstructed with this function every time the users clicks one of the items, using this:
$(".ac-big").customScrollbar("resize")
In order to make the transition run smooth I've used setInterval as in the example below:
<script type="text/javascript">
$(window).load(function () {
$(function(){
setInterval(function(){
$(".ac-big").customScrollbar("resize")
},100);
});
</script>
The problem is that the script is very resource consuming. There is no need to run this every 100 milliseconds. I want to make it run every 100 milliseconds for 1,5 seconds only after the users click on one radio button.
Here comes another problem. Since the accordion slider is built using radio buttons, how to call javascript functions on radio buttons click?
I have inserted setTimeout and setInterval into the tags because I believe I have to use a combination of those 2. If I had all the necessary building blocks I wouldn't be here wasting your time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…