Created
November 15, 2019 09:42
-
-
Save jwarby/e603b6fbbac5aa7a6266db015c729e7d to your computer and use it in GitHub Desktop.
Log out Bootstrap (v4) breakpoint changes (add as a snippet in Google Chrome/Chromium and then run)
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
function getResponseBreakpoint() { | |
const breakpoints = ['xl', 'lg', 'md', 'sm']; | |
return breakpoints.find((breakpoint) => { | |
const div = document.createElement("div"); | |
div.classList.add("d-none", `d-${breakpoint}-block`); | |
document.body.appendChild(div); | |
const style = window.getComputedStyle(div); | |
const visible = style.display !== "none"; | |
document.body.removeChild(div); | |
return visible; | |
}) || "xs"; | |
} | |
let currentBreakpoint = getResponseBreakpoint(); | |
console.info(`[bootstrap] current breakpoint = ${currentBreakpoint}`); | |
window.addEventListener("resize", () => { | |
const newBreakpoint = getResponseBreakpoint() | |
if (newBreakpoint !== currentBreakpoint) { | |
console.info(`[bootstrap] breakpoint changed = ${newBreakpoint}`); | |
currentBreakpoint = newBreakpoint; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment