Необходимо выбрать все элементы, которые к моменту выбора будут находиться в процессе анимации.
Решение
Для решения задачи применим фильтр :animated()(листинг 1.3.10).
Листинг 1 .3 .1 0 . Использование фильтра :animated()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru"> <head> <title>example-1-3-10</title> <content> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> <style type="text/css"> div { background-color:#ff0; border:1px solid #aaa; width:80px; height:80px; margin:0 5px; float:left; } div.colored { background:#008000; } </style> <script type="text/javascript"> $(function(){ $("#run").click(function(){ $("div:animated").toggleClass("colored"); }); function animateIt() { $("#mover").slideToggle("slow", animateIt); } animateIt(); }); </script> </head> <body> <button id="run">Run</button> </body> </html> |
Источник: Самков Г. А. jQuery. Сборник рецептов. — 2-е изд., перераб. и доп. — СПб.: БХВ-Петербург, 2011. — 416 с.: ил. + CD-ROM — (Профессиональное программирование)