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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 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.

HTML

              
                <div id="stalker"></div>
<div class="wrap">
  <a href="###">Stick Link</a>
  <a href="###" class="no_stick_">No Stick</a>
</div>
              
            
!

CSS

              
                #stalker {
    pointer-events: none;
    position: fixed;
    top: -8px;     //座標調節(カーソル位置と円の中心を合わせる)
    left: -8px;    //座標調節(カーソル位置と円の中心を合わせる)
    width: 16px;   //マウスストーカーの直径
    height: 16px;  //マウスストーカーの直径
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    transition: transform 0.2s, top, 0.5s, left 0.5s, width .5s, height .5s, background-color .5s;
    transition-timing-function: ease-out;
    z-index: 999;
    &.hov_{
      top: -32px;     //大きさに合わせて座標調節
      left: -32px;    //大きさに合わせて座標調節
      width: 64px;
      height: 64px;
      transition: .5s;
      background: rgba(255, 0, 0, 0.4);
    }
}


// マウスストーカーに関係ないCSS
.wrap{
  padding: 16px;
}
a{
    display: inline-block;
    color: #fff;
    text-decoration: none;
    padding: 8px 32px;
    margin: 16px;
    background: #666;
}

              
            
!

JS

              
                //マウスストーカー用のdivを取得
const stalker = document.getElementById('stalker');

//aタグにホバー中かどうかの判別フラグ
let hovFlag = false;

//マウスに追従させる処理 (リンクに吸い付いてる時は除外する)
document.addEventListener('mousemove', function (e) {
    if (!hovFlag) {
    stalker.style.transform = 'translate(' + e.clientX + 'px, ' + e.clientY + 'px)';
    }
});

//リンクへ吸い付く処理
const linkElem = document.querySelectorAll('a:not(.no_stick_)');
for (let i = 0; i < linkElem.length; i++) {
    //マウスホバー時
    linkElem[i].addEventListener('mouseover', function (e) {
        hovFlag = true;

        //マウスストーカーにクラスをつける
        stalker.classList.add('hov_');

        //マウスストーカーの位置をリンクの中心に固定
        let rect = e.target.getBoundingClientRect();
        let posX = rect.left + (rect.width / 2);
        let posY = rect.top + (rect.height / 2);

        stalker.style.transform = 'translate(' + posX + 'px, ' + posY + 'px)';

    });
    //マウスホバー解除時
    linkElem[i].addEventListener('mouseout', function (e) {
        hovFlag = false;
        stalker.classList.remove('hov_');
    });
}
              
            
!
999px

Console