This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var elements = Array.from(document.getElementsByClassName('fix-overflow')); | |
| elements.map(function(element) { | |
| if (element.scrollHeight > element.offsetHeight) { | |
| // is overflowing | |
| fixOverflow(element); | |
| } | |
| }); | |
| function fixOverflow(element) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var list = document.getElementById('list'); | |
| var listParent = list.parentElement; | |
| var listParentHeight = listParent.offsetHeight; // Yes-Yes: store height of parent element | |
| var removedList = listParent.removeChild(list); // Yes-Yes: remove list for batch editing | |
| var listItems = Array.from(removedList.children); | |
| for (var i = 0; i < listItems.length; i++) { | |
| listItems[i].style.marginTop = Math.floor( listParentHeight / listItems.length - 10) + 'px'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var list = document.getElementById('list'); | |
| var listItems = Array.from(list.children); | |
| for (var i = 0; i < listItems.length; i++) { | |
| var listParentHeight = list.parentElement.offsetHeight; // No-No: calculate parent height in every loop | |
| listItems[i].style.marginTop = Math.floor( listParentHeight / listItems.length - 10) + 'px'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .disable-hover, | |
| .disable-hover * { | |
| pointer-events: none !important; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var element = document.getElementById('example-element'); | |
| var parentElement = element.parentElement; | |
| var removedElement = parentElement.removeChild(element); // triggers reflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| removedElement.style.opacity = '0.5'; | |
| removedElement.style.padding = '20px 10px'; | |
| removedElement.style.width = '200px'; | |
| parentElement.appendChild(removedElement); // triggers reflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var element = document.getElementById('example-element'); | |
| element.style.display = 'none'; // hide the element, triggers reflow | |
| element.style.opacity = '0.5'; | |
| element.style.padding = '20px 10px'; | |
| element.style.width = '200px'; | |
| element.style.display = 'block'; // show the element again, triggers reflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| element.style.left = left; // triggers reflow | |
| element.style.top = top; // triggers reflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| element.style.cssText += "left: " + left + "px; top: " + top + "px;"; // triggers reflow once |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Vanilla JavaScript | |
| void element.offsetWidth; | |
| // or similarly | |
| void element.offsetHeight; | |
| // jQuery | |
| $("#element").width(); | |
| // or similarly | |
| $("#element").height(); |