I wrote a function to create one of those CSS triangle blocks and insert it right after one of the already created blocks.
function createArrow() {
var arrowDown = {
parent: document.querySelector('.landingItem'),
div: document.createElement('div'),
initDiv: function() {
this.div.classList.add('arrow-down');
this.div.style.borderLeftWidth = parseInt(document.documentElement.clientWidth)/2 + 'px';
this.div.style.borderRightWidth = parseInt(document.documentElement.clientWidth)/2 + 'px';
this.parent.appendChild(this.div);
},
checkDiv: function () {
if(this.parent.querySelector('.arrow-down')) {
this.parent.removeChild(this.parent.querySelector('.arrow-down'));
}
this.initDiv();
}
};
arrowDown.checkDiv();
}
createArrow();
window.addEventListener('resize', createArrow);
.arrow-down {
margin-top: -2px;
border-top: 60px solid #501a70;
border-left: 160px solid transparent;
border-right: 160px solid transparent;
}
<div class="landingItem"></div>
What can I improve?