Y
Y
Yuri2020-11-07 20:28:20
Python
Yuri, 2020-11-07 20:28:20

How to pause animation in JS?

There is a code https://jsfiddle.net/hibinyru/549vkdhx/3/ - this is an animation of static images.

Question 1. In this case, how can I pause this animation by clicking on the picture?

Question 2. Why does the animation speed up when the loop is executed several times, the further the faster

Thanks in advance

PS. I'm not very good at JS :( I took the finished code and filed it for myself. I can't write something new

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexey Yarkov, 2016-07-04
@nano_e_t_4

pattern = '<[^>]+>'
# выражение означает строку между символами < и >
# квантификатор + - один или более символов
# квантификатор * -  ноль или более символов
# квантификатор ? - ноль или один символ

That is, in the string with
this regular expression there is only<abc def>
>>> import re
>>> string = '<p style="margin-left:10px;">text<b class="super-bold">bold text</b>.<p>'
>>> string2 = '<abc def>gfh>'
>>> pattern = '<[^>]+>'
>>> 
>>> result = re.findall(pattern,string)
>>> print result
['<p style="margin-left:10px;">', '<b class="super-bold">', '</b>', '<p>']
>>> 
>>> result2 = re.findall(pattern,string2)
>>> print result2
['<abc def>']

A
Alexey, 2016-07-04
@alsopub

The result gets:
1) character < (<)
2) 1 or more characters other than > ([^>]+)
3) character > (>)
All this based on the regular expression <[^>]+>

A
abcd0x00, 2016-07-04
@abcd0x00

Read the documentation
https://docs.python.org/3/library/re.html

X
xmoonlight, 2016-07-04
@xmoonlight

<[^>]+>
The answer is simple: after opening, we look for everything that is inside until there is a closure.
those. (this is just an example FOR UNDERSTANDING, and the tag structure here, of course, is not correct):
or
<a sdfsd>>>>>- will be:<a sdfsd>

A
Arseny, 2020-11-08
@hibinyru

To “stop” a value, write it to a variable, which will allow you to start counting not from the very beginning. To be able to restore, write your interval to another variable and reset it for those events when you need it.
To eliminate speedup, check if you have a dependency on an incremented value or a nested loop.

D
Danil929292929, 2020-11-07
@Danil929292929

function stopAnimation() {
clearInterval(function);
}
And the second, I don't even know how to solve

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question