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

Auto Save

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 id="g-ms" class="g-ms">
  <div class="g-ms_i"></div>
</div>

<!-- 以下、ホバー確認用要素 -->
<div class="sampleWrapper">
  <p class="sampleTxt"><a href="#">テキストリンク</a></p>
  <div class="sampleBox msl">BOX</div>
</div>
              
            
!

CSS

              
                /* マウスストーカー */
.g-ms {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  transform: translate3d(50vw, 50vh, 0);
  pointer-events: none;
  transition: all 0.3s ease-out;
}
.g-ms_i {
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 30px;
  transition: all .3s ease;
  background: rgba(0,0,0,.05);
  opacity: 0;
}

/* アクティブ時 */
.g-ms.g-ms-active .g-ms_i {
  opacity: 1;
}

/* マウスホバー時 */
.g-ms.g-ms-hover {
  mix-blend-mode: difference;
}
.g-ms.g-ms-hover .g-ms_i {
  background: #fff;
  transform: scale(.2);
}

/* 以下、ホバー確認用要素のための記述 */
html, body {
  /* exclusionに影響するので背景色はきちんと指定 */
  background-color: #fff;
  height: 100%;
}
.sampleWrapper {
  padding: 50px 0;
}
.sampleTxt {
  text-align: center;
  margin: 0;
}
.sampleBox {
  width: 100px;
  margin: 50px auto 0;
  background: #333;
  color: #fff;
  line-height: 100px;
  text-align: center;
}
              
            
!

JS

              
                const mouseStalker = document.getElementById('g-ms');
let msPos = {
  // マウスストーカーの位置
  s: {
    x: document.documentElement.clientWidth / 2,
    y: document.documentElement.clientHeight / 2
  },
  // マウスポインターの位置
  m: {
    x: document.documentElement.clientWidth / 2,
    y: document.documentElement.clientHeight / 2
  }
};

// マウスストーカーをactiveにする
if (window.matchMedia( "(pointer: fine)" ).matches) {
  document.addEventListener ("mousemove", msActivate);
}
function msActivate() {
  mouseStalker.classList.add('g-ms-active');
  document.removeEventListener ("mousemove", msActivate);
  // mouseの位置セット
  document.addEventListener('mousemove', function(e){
    msPos.m.x = e.clientX;
    msPos.m.y = e.clientY;
  });
  // アニメーション開始
  requestAnimationFrame(msPosUpdate);
}

// マウスストーカーを動かす関数
function msPosUpdate() {
  msPos.s.x += (msPos.m.x - msPos.s.x) * 0.1;
  msPos.s.y += (msPos.m.y - msPos.s.y) * 0.1;
  const x = Math.round(msPos.s.x * 10) / 10;
  const y = Math.round(msPos.s.y * 10) / 10;
  mouseStalker.style.transform = `translate3d(` + x + 'px,' + y + 'px, 0)';
  requestAnimationFrame(msPosUpdate);
}

// hover時にclass追加
const stalkerLinkObj = document.querySelectorAll('a, button, .msl');
for (let i = 0; i < stalkerLinkObj.length; i++) {
  stalkerLinkObj[i].addEventListener('mouseover', function(){
    mouseStalker.classList.add('g-ms-hover');
  });
  stalkerLinkObj[i].addEventListener('mouseout', function(){
    mouseStalker.classList.remove('g-ms-hover');
  });
}
              
            
!
999px

Console