var btnReady = document.getElementById ('ready');
btnReady.addEventListener ('click', function () {
pasteText (h2, sayPhrase [0]);
changeCss (h2, 'color', '# 000');
changeCss (lampImg1, 'display', 'none');
changeCss (btnRepeat, 'cursor', 'default');
changeCss (lampImg2, 'display', 'block');
changeCss (dontClick, 'display', 'none');
changeCss (btnReady, 'display', 'none');
changeCss (btnRepeat, 'display', 'block');
play ('audio / LightSwitch.mp3');
changeCss (rightBlock, 'backgroundColor', "# 000");
changeCss (leftBlock, 'backgroundColor', "# fff");
changeCss (rightBlock, 'backgroundImage', "url (img / troll.png)");
setAnimate (lampImg2, 'animated swing');
}, false);
function changeCss (node, selector, property) {
node.style [selector] = property;
}
|
1 answer
Everything is fine with you, but I would changeCss function into this:
var btnReady = document.getElementById('ready'); btnReady.addEventListener('click', function(){ changeCss(btnReady, {'background-color': 'red', 'color': 'white', 'border': '0'}) }, false); function changeCss(obj, styles) { for(key in styles){ obj.style[key] = styles[key]; }; }; <button id="ready">Клик</button> |
changeCssyour function? - Yuri