babbel cod es2015
document.addEventListener('DOMContentLoaded', ready);
function rand(x) {
return Math.random() * x - x * 0.5 + 'px';
}
function ready() {
var sections = document.querySelectorAll('div .section');
for (var i = 0; i < sections.length; ++i) {
var box = sections[i].querySelector('.text');
if (box) {
(function() {
var hideText = function hideText(intel) {
var t = intel.querySelector('.text');
[]
.concat(_toConsumableArray(t.querySelectorAll('div')))
.forEach(function(n, i) {
Object.assign(n.style, {
opacity: 0,
transform:
'translate3d(' +
rand(400) +
', ' +
rand(400) +
', ' +
rand(60) +
')'
});
});
};
var showText = function showText(intel) {
var t = intel.querySelector('.text');
console.log(t);
[]
.concat(_toConsumableArray(t.querySelectorAll('div')))
.forEach(function(n, i) {
Object.assign(n.style, {
opacity: 1,
transform: 'translate3d(0, 0, 0)'
});
});
};
box.innerHTML = []
.concat(_toConsumableArray(box.textContent))
.map(function(n) {
return '<div>' + (n.trim() ? n : ' ') + '</div>';
})
.join('');
hideText(sections[i]);
sections[i].addEventListener('mouseenter', function(e) {
showText(this);
});
sections[i].addEventListener('mouseleave', function(e) {
hideText(this);
});
})();
}
}
}
вот проблемный участок
(function() {
var hideText = function hideText(intel) {
var t = intel.querySelector('.text');
[]
.concat(_toConsumableArray(t.querySelectorAll('div')))
.forEach(function(n, i) {
Object.assign(n.style, {
opacity: 0,
transform:
'translate3d(' +
rand(400) +
', ' +
rand(400) +
', ' +
rand(60) +
')'
});
});
};