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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div class="outer">
  <img src="http://opsundbay.com/Media/collection/20010104/20010104_hd.jpg"


.outer img{width:100%;height:auto;}
              //Get the div
var _imgDiv = document.getElementsByClassName("outer")[0];

var _sw = 0, _sh = 0, _scrollAmount = 0, _windowScrollY = 0, _zoomLevel = 1;
var _percentScrolled = 0, _xOffset = 0, _yOffset = 0, _imgRel = 2000/3600, _mx = 0, _my = 0;

//Get stage size
function resized(e){
  _sh = window.innerHeight;
  //Set document height in order for browser scroll to control zoom level
  _scrollAmount = _sh*1.5;
  document.body.style.height = _sh+_scrollAmount + "px";
  _sw = window.innerWidth;
  _imgDiv.style.width = _sw + "px";
  _mx = _sw*.5, _my = 0;//This is not needed, but makes the thumbnail on codepen look nice ;-)
window.addEventListener("resize", resized);

function scrolled(e){
  _windowScrollY = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  //Calculate percentage scrolled (zoom level)
  _percentScrolled = (_scrollAmount-_windowScrollY)/_scrollAmount;
window.addEventListener("scroll", scrolled);

function moved(e){
  _mx = e.clientX, _my = e.clientY;
document.body.addEventListener("mousemove", moved);

//Start render engine
TweenLite.ticker.addEventListener("tick", engine);
function engine(e){
  //Tween zoom level
  _zoomLevel += ((_percentScrolled+1)-_zoomLevel)*.1;
  //Calculate new offsets
  var _curImgH = (_percentScrolled+1)*(_sw/_imgRel);
  var _offY = -_my/_sh * (_curImgH-_sh);
  var _curImgW = (_percentScrolled+1)*_sw;
  var _offX = -(_mx/_sw-.5) * (_curImgW-_sw);
  //Tween offsets
  _yOffset += (_offY-_yOffset)*.1;
  _xOffset += (_offX-_xOffset)*.1;
  TweenLite.set(_imgDiv, {x:_xOffset, y:_yOffset, scale:_zoomLevel, force3D:true, transformOrigin:"50% 0"});
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.