cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <!-- 
For CSS Grid expertise:
Rachel Andrew: https://gridbyexample.com/
Jen Simmons: http://labs.jensimmons.com/
 -->
<div id="holder">
  <div id="left">
    <div id="grid">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t1.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t2.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t3.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t4.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t5.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t6.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t7.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t8.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t9.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t10.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t11.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t12.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t13.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t14.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t15.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t16.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t17.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t18.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t19.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t20.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t21.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t22.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t23.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t24.jpg">
      <img src="https://www.andybarefoot.com/codepen/images/trump/t25.jpg">
    </div>
    <p id="toggle">Toggle Grid Lines</p>
  </div>
  <div id="text">
    <h1>Orange</h1>
    <p>I once had a book full of amazing Macromedia Flash experiments, one of which was an image of the Mona Lisa that would morph as you moved the mouse over it.</p>
    <p>And as @LawrieCape kindly reminded me in the comments, it was by Yugo Nakamura in "New Masters of Flash".</p>
    <p>Anyway, this is my version of that experiment using CSS Grid to morph the image.</p>
  </div>
</div>

            
          
!
            
              body {
  color: #FFFCF2;
  background-color: #ff6600;
  font-family: Helvetica, Arial, Sans-Serif;
  text-align: center;
}
h1 {
  margin-top: 2vh;
  font-size: 1.8em;
}
p {
  margin-top: 2vh;
  font-size: 1.2em;
}
#toggle{
  text-decoration: underline;
}

#holder {
  display: grid;
  grid-template-columns: 90vh 1fr;
  margin: 3vh 5vh 0 5vh;
  grid-gap: 2vh;
}

#grid {
  display: grid;
  width: 90vh;
  height: 90vh;
  grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows:  1fr 1fr 1fr 1fr 1fr;
  grid-gap: 0;
}

img {
  width: 100%;
  height: 100%;
  -webkit-user-select:none;
  -webkit-touch-callout:none;
}
#left {
  width: 90vh;
}
#text {
  text-align: left;
  padding-bottom: 20px;
}
@media  (orientation:portrait) {
  #holder {
    grid-template-columns: 1fr;
  }
  #grid {
    width: 90vw;
    height: 90vw;
  }
  #left {
    width: 90vw;
  }
}
            
          
!
            
              var lines = false;
$("#grid").mousemove(function( event ) {
  var leftPer = (event.clientX - $("#grid").offset().left)/$("#grid").width();
  var topPer = (event.clientY - $("#grid").offset().top)/$("#grid").height();
  console.log(leftPer);
  console.log(topPer);
  console.log("--------");
  colStr = "";
  rowStr = "";
  for(i=0;i<5;i++){
    nearX = 1 - (Math.abs(leftPer - (0.1+0.2*i)));
    colStr += " " +  (1 + Math.pow(nearX*5,2))  + "fr";
  }
  for(j=0;j<5;j++){
    nearY = 1 - (Math.abs(topPer - (0.1+0.2*j)));
    rowStr += " " + (1 + Math.pow(nearY*5,2)) + "fr";
  }
  console.log(colStr);
  console.log(rowStr);
  $("#grid").css('grid-template-rows', rowStr);
  $("#grid").css('grid-template-columns', colStr);
});
$("#grid").mouseout(function() {
  $("#grid").css('grid-template-rows', "1fr 1fr 1fr 1fr 1fr");
  $("#grid").css('grid-template-columns', "1fr 1fr 1fr 1fr 1fr");
});
$("#toggle" ).click(function() {
  if(lines){
    lines=false;
    $("#grid").css('grid-gap', "0");
  }else{
    lines=true;
    $("#grid").css('grid-gap', "1px");
  }
});
            
          
!
999px
Loading ..................

Console