D
D
DeniSidorenko2020-05-05 06:54:31
JavaScript
DeniSidorenko, 2020-05-05 06:54:31

How to set click limits js?

Hello, I have this code

$('.home-dot').on('click',function(){


    var idx = $(this).index()

    $('.home-dot').removeClass('active')
    $(this).addClass('active')


  })


Tell me how to make the click function when clicking on home-dot run no more than 0.5 seconds. He pressed the function is executed. But if he pressed once, then after 0.1 second again, it would not be executed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleks0123456789, 2020-05-05
@Aleks0123456789

Try underscorejs.ru/#throttle

M
mahmudchon, 2020-05-05
@mahmudchon

As an example:

I 'm highlighting blocks with red styles just to demonstrate that at this point, clicking again on this block or any .home-dot will not work. Put 2 seconds for clarity.
I want to show the one on which .active
is now. It can be made even simpler and completely different, but I think the logic is clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question