Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   как добавить класс элементам с определенным интервалом (https://javascript.ru/forum/events/51063-kak-dobavit-klass-ehlementam-s-opredelennym-intervalom.html)

рони 24.10.2014 03:40

:-? :write:
<style>
  .red {
    color: red;
  }
</style>
<p class="hello">Lorem ipsum dolor sit amet, consectetur</p>
<p class="hello">Sapiente in delectus dolorem reiciendis ditii</p>
<p class="hello">Quis dolore autem voluptatibus repellat</p>
<script>
      var pAll = document.querySelectorAll('p.hello'), i = 0, p,
      timer = setInterval(function () { p = pAll[i++];
      p ?  p.classList.add('red') : clearInterval(timer)
    }, 2000);
</script>

Vlasenko Fedor 24.10.2014 12:01

рони,
http://caniuse.com/#search=classList
и так в скором времени ты напишешь мой вариант :)
<style>
  .red {
    color: red;
  }
</style>
<p class="hello">Lorem ipsum dolor sit amet, consectetur</p>
<p class="hello">Sapiente in delectus dolorem reiciendis ditii</p>
<p class="hello">Quis dolore autem voluptatibus repellat</p>
<script>
var allP = document.querySelectorAll('p.hello'),
    len = allP.length,
    i = 0,
  timer = setInterval(function () {
    len-- 
	? allP[i++].className += ' red'
	: clearInterval(timer);
  }, 2000);
</script>

ksa 24.10.2014 14:48

Цитата:

Сообщение от Poznakomlus
в скором времени ты напишешь мой вариант

Так он и твой сильно поменялся по отношении к первому варианту. :D

BETEPAH 24.10.2014 16:57

А стартер хоть бы раз появился в ветке ;)

Smike 26.10.2014 12:50

Большое спасибо всем вам за помощь. Этот топик показывает, что одну и ту же задачу можно решить разными способами на js


Часовой пояс GMT +3, время: 05:28.