Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- var section = document.getElementsByTagName('section')[0];
- var sectionInitialColor = window.getComputedStyle(section, null).getPropertyValue('background-color');
- var timer;
- var interval;
- var currentTime = 0;
- var time = 10000;
- var elapsedTime = 0;
- var childh = section.getElementsByTagName('h2');
- var p;
- section.addEventListener('click', function(e) {
- section.style.backgroundColor = 'DarkViolet';
- currentTime = currentTime - elapsedTime + time;
- clearTimeout(timer);
- clearInterval(interval);
- elapsedTime = 0;
- timer = setTimeout(function() {
- if(section.style.backgroundColor === sectionInitialColor) {
- currentTime = 0;
- } else {
- currentTime -= time;
- }
- section.style.backgroundColor = sectionInitialColor;
- }, currentTime);
- interval = setInterval(function() {
- elapsedTime += 1000;
- }, 1000);
- });
- for(let i = 0; i < childh.length; i++) {
- childh[i].addEventListener('click', function(e) {
- p = document.createElement('p');
- p.textContent = childh[i].textContent;
- section.appendChild(p);
- e.stopPropagation();
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement