| Current Path : /home/kamilrogam/lab/eduBulb/assets/ |
| Current File : /home/kamilrogam/lab/eduBulb/assets/init.js |
/*jshint esversion:6,browser:true,devel: true*/
window.addEventListener('load', function () {
const elements = document.querySelectorAll('.el');
elements.forEach(function (el) {
let R = Math.floor(Math.random() * 150) + 1;
let G = Math.floor(Math.random() * 150) + 1;
let B = Math.floor(Math.random() * 150) + 1;
el.style.backgroundColor = `rgb(${R}, ${G}, ${B})`;
if (el.classList.contains('el-img')) {
let elImg = el.querySelector('img');
let ImgWidth = elImg.width;
let ImgHeight = elImg.height;
let elComp = window.getComputedStyle(el)
if (ImgWidth < ImgHeight) {
elImg.style.width = ImgWidth + 'px';
elImg.style.height = ImgHeight + 'px';
el.style.height = ImgHeight + 'px';
let a1 = Number(elComp.width.replace('px',''));
let a2 = Number(elComp.height.replace('px',''));
el.style.paddingLeft = (a2 - a1)/2 + 50 +'px';
el.style.paddingRight = (a2 - a1)/2 + 50 +'px';
} else if (ImgWidth > ImgHeight) {
elImg.style.width = ImgWidth + 'px';
elImg.style.height = ImgHeight + 'px';
el.style.height = ImgHeight + 'px';
let a1 = Number(elComp.width.replace('px',''));
let a2 = Number(elComp.height.replace('px',''));
el.style.paddingTop = (a1 - a2)/2 + 50 +'px';
el.style.paddingBottom = (a1 - a2)/2 + 50 +'px';
} else {}
}
});
});