Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <div class="menu"><p class="screenSize"></p><p class="gridSize"></p></div>
  <div class="nav">
    <button type="button" class="navToggle">btn
  </div>
  <div class="c1 col"></div>
  <div class="c2 col"></div>
  <div class="c3 col"></div>
  <div class="c4 col"></div>
  <div class="c5 col"></div>
  <div class="c6 col"></div>
  <div class="c7 colHide6 col"></div>
  <div class="c8 colHide6 col"></div>
  <div class="c9 colHide6 col"></div>
  <div class="c10 colHide6 col"></div>
  <div class="c11 colHide6 col"></div>
  <div class="c12 colHide6 col"></div>
  <div class="sidebar">
    <div class="handle"></div>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --navSize: 304px;
  --sidebarSize: 64px;
  --gutterSize: 40px;
  --colNumber: 12;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.wrapper > div {
  border: 2px solid rgb(233, 171, 88);
  border-radius: 4px;
  background-color: rgba(233, 171, 88, 0.5);
  text-align: center;
  color: #d9480f;
}

.handle {
  /*   position: relative; */
  height: 100%;
  width: 2px;
  background: red;
  /*   justify-self: start; */
}

/* >= 320px 4col */
  .wrapper {
    display: grid;
    grid-gap: 16px;
    grid-template-areas:
	"menu menu menu menu"
	"nav nav nav sidebar"
  "c1 c2 c3 c4"       
  }

/* >= 768px 6col */
/* @media only screen and (min-width: 768px) {
  .wrapper {
    grid-template-columns: 20% auto;
    grid-template-areas:
      "header   header"
      "sidebar  content"
      "sidebar2 sidebar2"
      "footer   footer";
  }
}
 */

/* >= 1280px 12col */
/* @media only screen and (min-width: 1280px) {
  .wrapper {
    display: grid;
    grid-template-columns: var(--navSize) repeat(var(--colNumber), auto) var(
        --sidebarSize
      ) [end];
    grid-template-rows: 64px 100vh; */
    /* 	grid-template-areas:
	"menu menu menu menu menu menu menu menu menu menu menu menu menu menu"
	"nav c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 sidebar"; */
/*     column-gap: var(--gutterSize);
    row-gap: 10px;
  }
} */

/* .menu { */
  /*   grid-area: 1/1/1/15; */
/*   grid-column-start: 1;
  grid-column-end: 15;
  display: flex;
  justify-content: space-around;
} */
              
            
!

JS

              
                // Animation
// Duration
const speedSm = 0.01; // 100ms
const speedMdEnter = 0.25; // 250ms
const speedMdExit = 0.2; // 200ms
const speedLgEnter = 0.3; // 300ms
const speedLgExit = 0.25; // 250ms

// Standard curve (On screen)
CustomEase.create("GSAPStandard", "0.4, 0.0, 0.2, 1");

// Deceleration (Enter screen)
CustomEase.create("GSAPDeceleration", "0.0, 0.0, 0.2, 1");

// Acceleration (Leave screen)
CustomEase.create("GSAPAcceleration", "0.4, 0.0, 1, 1");

TweenLite.defaultEase = CustomEase.create("GSAPStandard", "0.4, 0.0, 0.2, 1");

// Selector
let select = s => document.querySelector(s),
  selectAll = s => document.querySelectorAll(s),
  menu = select(".menu"),
  nav = select(".nav"),
  sidebar = select(".sidebar"),
  handle = select(".handle"),
  wrapper = select(".wrapper"),
  navToggle = select(".navToggle"),
  screenSize = select(".screenSize"),
  gridSize = select(".gridSize"),
  allCol = selectAll(".col"),
  colHide6 = selectAll(".colHide6"),

  // CSS variables
  root = select(":root"),
  rootStyles = getComputedStyle(root);
  // navSize = rootStyles.getPropertyValue('--navSize');

// Media queries
const mobile = window.matchMedia("(maxwidth: 320px)");
mobile.addListener(colNumChange);
colNumChange(desktop);

function colNumChange(mq) {
    if (mq.matches) {
        console.log("mobile");
    } else {
        // console.log("less than desktop");
    }
}

// Grid size
let desktopMargin = 40;
let desktopGutter = 40;
let gridTotalWidth = 0;
let allMargin = desktopMargin * 2;
let allGutter = desktopGutter * 11;

updateGridInfo();

function calculateGridSize(){
  gridTotalWidth = 0;

  allCol.forEach(function(e){
    gridTotalWidth += parseInt(e.offsetWidth);
  });

  return gridTotalWidth += allMargin + allGutter;
}

function updateGridInfo(){
  calculateGridSize();
  return gridSize.innerHTML = "Grid: " + gridTotalWidth;
}

// Screen size
let navWidth = nav.offsetWidth;
let sidebarWidth = sidebar.offsetWidth;
let screenWidth = window.innerWidth;
let screenHeight = window.innerHeight;

function updateScreenInfo(){
  return screenSize.innerHTML = "Screen: " + screenWidth + " x " + screenHeight;
}

updateScreenInfo();

window.addEventListener("resize", () => {
  screenWidth = window.innerWidth;
  screenHeight = window.innerHeight;
  
  updateScreenInfo();
  updateGridInfo();
  
  if(gridTotalWidth <= 700){
    colHide6.forEach(function(e){
      e.style.display = "none";  
    });

    // menu.style["grid-column-end"] = 9;
    menu.style.setProperty("grid-column-end", 9);
    root.style.setProperty("--colNumber", 6);
    rootStyles = getComputedStyle(root);
    colNumber = rootStyles.getPropertyValue("--colNumber");
    // wrapper.style["grid-template-columns"] = navWidth + "px repeat(6, auto) " + sidebarWidth + "px";
  }
});

// Resizable
let handleZone = document.createElement("div");
let posX = 0;

Draggable.create(handleZone, {
  type: "x",
  trigger: handle,
  cursor: "ew-resize",
  onRelease: function() {
    TweenMax.to(sidebar, 0.25, {
      backgroundColor: "rgba(233, 171, 88, 0.5)",
      borderColor: "rgb(233, 171, 88)"
    });
  },
  onDrag: updateSidebar,
  onPress: function() {
    posX = this.x;
    TweenMax.to(sidebar, 0.25, {
      backgroundColor: "#ddd",
      borderColor: "#888"
    });
  }
});

function updateSidebar() {
  let diffX = this.x - posX;
  posX = this.x;

  sidebarWidth = clamp(sidebarWidth - diffX, 64, 400);
wrapper.style.setProperty("grid-template-columns", navWidth + "px repeat(12, auto) " + sidebarWidth + "px");
  // wrapper.style.setProperty("grid-template-columns", navWidth + "px repeat(" + var(--colNumber) + ", auto) " + sidebarWidth + "px");
  // fix here
  updateGridInfo();
}

function clamp(value, min, max) {
  return Math.max(min, Math.min(value, max));
}

// Expand + collapse nav
function collapse() {
  navWidth = 64;
  wrapper.style.setProperty("grid-template-columns", navWidth + "px repeat(12, auto) " + sidebarWidth + "px");
  updateGridInfo();
}
function expand() {
  navWidth = 304;
  wrapper.style.setProperty("grid-template-columns", navWidth + "px repeat(12, auto) " + sidebarWidth + "px");
  updateGridInfo();
}

navToggle.addEventListener("click", () => {
  return (this.tog = !this.tog) ? collapse() : expand();
});
              
            
!
999px

Console