Pen Settings

HTML

CSS

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

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

              
                <main id="main">
  <canvas id="view"></canvas>
  <section id="text" class="ctn-text">
    <h1 class="efet-text">Efetivos</h1>
  </section>
</main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Meddon');

main {
  position: fixed;
  overflow: hidden;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;  
  background: #000;
}

#view {
  position: absolute;
  top: 0;
  left: 0;
}

.ctn-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;  
  display: flex;
  justify-content: center;
  align-items: center;
  
  cursor: pointer;
   
  .efet-text {
    font-family: 'Meddon', cursive;
    color: #fff;
    font-size: 140px;
    cursor: pointer;
    margin-top: -8vh;
  }
}
              
            
!

JS

              
                console.clear();

const baseUrl = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/";

const maskSpeed = 0.1;
const maskRadius = 225;

const main = document.querySelector("#main");
const text = document.querySelector("#text");
const view = document.querySelector("#view");

const app = new PIXI.Application({
  width: main.clientWidth,
  height: main.clientHeight,
  antialias: true,
  view
});

const screen = app.screen;
const bgSize = new PIXI.Rectangle(0, 0, 1920, 1080);
const pointer = new PIXI.Point(screen.width / 2, screen.height / 2);

const mask = new PIXI.Graphics()
  .beginFill(0xFFFFFF, 1)
  .drawCircle(0, 0, maskRadius)
  .endFill()

const maskPosition = mask.position;

const bulgeCenter = new PIXI.Point(0.5, 0.5);
const bulgeFilter = new PIXI.filters.BulgePinchFilter(bulgeCenter, maskRadius, 0.9);

const bgContainer = new PIXI.Container();
const bgTexture = PIXI.Texture.fromImage(`${baseUrl}interactive-bg.jpg?v=1`);

const bg1 = PIXI.Sprite.fromImage(`${baseUrl}interactive-bg-mask.jpg?v=1`);
bg1.alpha = 0.6;
bg1.anchor.set(0.5);

const bg2 = new PIXI.Sprite(bgTexture);
bg2.alpha = 0;
bg2.anchor.set(0.5);

const bg3 = new PIXI.Sprite(bgTexture);
bg3.anchor.set(0.5);
bg3.filters = [bulgeFilter];
bg3.filterArea = screen;
bg3.mask = mask;

bgContainer.addChild(bg1, bg2, bg3);

const tl = new TimelineMax();
buildTimeline();

tl.reverse()
  .timeScale(2);

let resized = true;
let updatePosition = true;

app.stage.interactive = true;
app.stage.filterArea = screen;
app.stage.addChild(bgContainer, mask);

app.stage
  .on("pointerdown", onPointerMove)
  .on("pointermove", onPointerMove)

app.ticker.add(onTick);
window.addEventListener("resize", () => resized = true);
text.addEventListener("click", () => tl.reversed(!tl.reversed()));


//
// ON TICK
// ===========================================================================
function onTick(delta) {
  
  if (resized) {
    onResize();
    updatePosition = true;
    resized = false;
  }
  
  if (updatePosition) {
    
    const dx = pointer.x - maskPosition.x;
    const dy = pointer.y - maskPosition.y;
    
    if (Math.abs(dx) < 0.05 && Math.abs(dy) < 0.05) {
      
      maskPosition.copy(pointer);
      updatePosition = false;
      
    } else {
      
      const dt = 1 - Math.pow(1 - maskSpeed, delta);
      maskPosition.x += dx * dt;
      maskPosition.y += dy * dt;     
    }
    
    bulgeCenter.x = maskPosition.x / screen.width;
    bulgeCenter.y = maskPosition.y / screen.height;
  }
}

//
// ON RESIZE
// ===========================================================================
function onResize() {
    
  const width = main.clientWidth;
  const height = main.clientHeight;  
  
  const scaleX = width / bgSize.width;
  const scaleY = height / bgSize.height;
  const scale = Math.max(scaleX, scaleY);
      
  app.renderer.resize(width, height);
    
  bgContainer.scale.set(scale);
  bgContainer.position.set(width / 2, height / 2);  
  
  pointer.x = clamp(pointer.x, 0, width);
  pointer.y = clamp(pointer.y, 0, height);
  
  buildTimeline();
}

//
// BUILD TIMELINE
// ===========================================================================
function buildTimeline() {
  
  const ease = Power3.easeInOut;  
  const size = Math.sqrt(screen.width * screen.width + screen.height * screen.height);
  const scale = size / maskRadius;
  
  const progress = tl.progress() || 0;
  const reversed = tl.reversed() || false;
  
  tl.progress(0).clear()
    .to(bulgeFilter, 3, { strength: 0, ease }, 0)
    .to(mask, 4, { pixi: { scale }, ease }, 0)
    .to(bg1, 2, { alpha: 0, ease }, 2)  
    .to(bg2, 2, { alpha: 1, ease }, 2)
    .progress(progress)
    .reversed(reversed)
}

//
// ON POINTER MOVE
// ===========================================================================
function onPointerMove(eventData) {
  pointer.copy(eventData.data.global);
  updatePosition = true;
}

function clamp(value, min, max) {
  return value <= min ? min : (value >= max ? max : value);
}


              
            
!
999px

Console