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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                  <div id="stkr-area">
    <div id="stkr"></div>
    <div class="ttl">←マウスストーカー</div>
    <div class="links">
      <div><a href="#" class="stkr-target" data-color="color1">リンク1</a></div>
      <div><a href="#" class="stkr-target" data-color="color2">リーーンク2</a></div>
      <div><a href="#" class="stkr-target" data-color="color3">リーーーーンク3</a></div>
    </div>
  </div>

  <!-- JavaScript -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
              
            
!

CSS

              
                    /* マウスストーカー */
    #stkr{
      position: absolute;
      top: 10px;
      left: 10px;
      width: 25px;
      height: 25px;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      transition: 0.2s;
      transition-timing-function: ease-out;
      pointer-events: none;
      z-index: 10;
    }
    /* マウスストーカーの可動範囲 */
    #stkr-area{
      width: 100%;
      height: 300px;
      padding: 10px;
      box-sizing: border-box;
      position: relative;
      background-color: rgb(184, 149, 247, 0.5);
    }
    /* ホバーした時の色 */
    .color1{ background-color: rgb(247, 77, 155, 0.5) !important; }
    .color2{ background-color: rgb(77, 200, 247, 0.6) !important; }
    .color3{ background-color: rgb(77, 247, 82, 0.5) !important; }

    /* マウスストーカーに影響のない装飾CSS */
    *{ margin: 0;  padding: 0; }
    html, body{ width: 100%; height: 100%; }
    .ttl{ padding-left: 30px; }
    .links div{ margin: 20px 10px; }
              
            
!

JS

              
                    // マウスストーカー関連の要素(任意で変更してください)
    const mouseStalker = "#stkr";           // マウスストーカーになる要素を指定
    const mouseTarget = ".stkr-target";     // リンクなどアクションを付けたい要素を指定
    const mouseStalkerArea = "#stkr-area";  // マウスストーカーが機能する要素を指定

    // 処理で使う変数たち
    const stkrSize = parseInt($(mouseStalker).css("width").replace(/px/, ""));
    const stkrPosX = parseInt($(mouseStalker).css("left").replace(/px/, ""));
    const stkrPosY = parseInt($(mouseStalker).css("top").replace(/px/, ""));
    const cssPosAjust = stkrPosX + (stkrSize / 2);
    let stkrFix = false;
    let scale = 1;
    let scroll = 0;

    // 追従用の処理
    $(mouseStalkerArea).hover(function(){
      $(mouseStalkerArea).mousemove(function(e){
        if(stkrFix == false){
          let x = e.clientX - cssPosAjust;
          let y = e.clientY + scroll - cssPosAjust;
          $(mouseStalker).css({
            "transform": "translate(" + x + "px," + y + "px) scale(" + scale + ")",
          });
        }
      });
    }, function(){
      $(mouseStalker).css({
        "transform": ""
      });
    });

    // リンクホバーの処理
    $(mouseTarget).hover(function(){
      stkrFix = true;
      scale = 2;
      let _width = parseInt($(this).css("width").replace(/px/,""));
      let _top = $(this).position().top;
      let _left = $(this).position().left;
      let x = _left - stkrPosX - (stkrSize / 2) + (_width / 2);
      let y = _top - stkrPosX;
      $(mouseStalker).css({
        "transform": "translate(" + x + "px," + y + "px) scale(" + scale + ")",
      }).addClass($(this).data("color"));
    }, function(){
      stkrFix = false;
      scale = 1;
      $(mouseStalker).removeClass($(this).data("color"));
    });

    $(window).scroll(function(){
      scroll = $(window).scrollTop();
    });
              
            
!
999px

Console