Skip to content

Instantly share code, notes, and snippets.

@jwarby
Created November 15, 2019 09:42
Show Gist options
  • Save jwarby/e603b6fbbac5aa7a6266db015c729e7d to your computer and use it in GitHub Desktop.
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)
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