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

              
                <h1>Change mouse pointer in designated area <br>(Vanilla JS)</h1>

<ul>
  <li>
    <h2 class="js-cursor-elm01 cursor-none">写真(標準のポインタを消す)</h2>
  </li>
  <li>
    <h2><a href="" class="js-cursor-elm02 cursor-none">リンク(標準のポインタを消す)</a></h2>
  </li>
</ul>
<ul>
  <li>
    <h2 class="js-cursor-elm01">写真(標準のポインタを残す)</h2>
  </li>
  <li>
    <h2><a href="" class="js-cursor-elm02">リンク(標準のポインタを残す)</a></h2>
  </li>
</ul>
<!-- 表示させるマウスポインタ01 -->
<div class="js-cursor-pointer01 cursor-pointer"><img src="https://coding-memo.work/wp-content/uploads/2022/03/dog.jpg" alt="" width="500" height="500"></div>
<!-- 表示させるマウスポインタ02 -->
<div class="js-cursor-pointer02 cursor-pointer"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M279.6 160.4C282.4 160.1 285.2 160 288 160C341 160 384 202.1 384 256C384 309 341 352 288 352C234.1 352 192 309 192 256C192 253.2 192.1 250.4 192.4 247.6C201.7 252.1 212.5 256 224 256C259.3 256 288 227.3 288 192C288 180.5 284.1 169.7 279.6 160.4zM480.6 112.6C527.4 156 558.7 207.1 573.5 243.7C576.8 251.6 576.8 260.4 573.5 268.3C558.7 304 527.4 355.1 480.6 399.4C433.5 443.2 368.8 480 288 480C207.2 480 142.5 443.2 95.42 399.4C48.62 355.1 17.34 304 2.461 268.3C-.8205 260.4-.8205 251.6 2.461 243.7C17.34 207.1 48.62 156 95.42 112.6C142.5 68.84 207.2 32 288 32C368.8 32 433.5 68.84 480.6 112.6V112.6zM288 112C208.5 112 144 176.5 144 256C144 335.5 208.5 400 288 400C367.5 400 432 335.5 432 256C432 176.5 367.5 112 288 112z"/></svg></div>

<h2>スライダーの中でも呼び出せます</h2>
<div class="swiper">
  <div class="swiper-wrapper">
    <div class="swiper-slide">
      <a href="" class="js-cursor-elm03">
        <p>標準のポインタを残す</p>
        <img src="https://picsum.photos/id/103/400/300" alt="" width="400" height="300">
      </a>
    </div>
    <div class="swiper-slide">
      <a href="" class="js-cursor-elm03 cursor-none">
        <p>標準のポインタを消す</p>
        <img src="https://picsum.photos/id/1003/400/300" alt="" width="400" height="300">
      </a>
    </div>
    <div class="swiper-slide">
      <a href="" class="js-cursor-elm03">
        <p>標準のポインタを残す</p>
        <img src="https://picsum.photos/id/90/400/300" alt="" width="400" height="300">
      </a>
    </div>
  </div>
  <div class="swiper-pagination"></div>
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>
</div>
<!-- 表示させるマウスポインタ03 -->
<div class="js-cursor-pointer03 cursor-pointer">テキストを<br>表示させる</div>

              
            
!

CSS

              
                .cursor-pointer {
  visibility: hidden;
  opacity: 0;
  position: fixed;
  z-index: 10;
  transform: scale(0);
  height: 160px;
  width: 160px;
  margin: -80px 0 0 -80px;
  transition: transform .3s,opacity .3s,visibility .3s;
  pointer-events: none;
}
.cursor-pointer.is-active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}
.cursor-none {
  cursor: none;
}


/* テストページ用style */
.js-cursor-pointer01 {
  height: 200px;
  width: 200px;
  margin: -100px 0 0 -100px;
}
.js-cursor-pointer01 img {
  height: 100%;
  width: 100%;
  object-fit: cover;
}
.js-cursor-pointer02 {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: #f1f1f1;
  box-shadow: 5px 5px 10px 0 rgba(0, 0, 0, 0.2);
}
.js-cursor-pointer02 svg {
  display: block;
  width: 60px;
}
.js-cursor-pointer03 {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: #fff;
  border: 1px solid #ccc;
}
.js-cursor-elm03 {
  display: block;
}

body {
  margin: 0;
  padding: 50px 0;
  text-align: center;
}
h1 {
  text-align: center;
  margin-bottom: 80px;
  font-size: 36px;
}
img {
  height: auto;
  max-width: 100%;
  vertical-align: top;
}
ul {
  display: flex;
  justify-content: center;
  list-style: none;
  padding: 0 40px;
  margin: 0 0 100px;
}
ul + ul {
  margin-top: -50px;
}
li {
  margin: 0 50px;
}
.swiper {
  padding-bottom: 60px;
}
.swiper img {
  width: 100%;
}
              
            
!

JS

              
                //指定エリアでマウスポインタを変更する関数 target:表示エリア, pointer:表示させたいポインタ
const changeCursor = (target, pointer) => {
	//ポインタがない場合は終了
	if(!window.matchMedia('(pointer: fine)').matches) {
		return;
	}

	//対象が存在しない場合は終了
	const pointerAreas = document.querySelectorAll(target);
	const targetPointer = document.querySelector(pointer);
	if(pointerAreas.length === 0 || !targetPointer) {
		return;
	}

	//ポインタ設定
	pointerAreas.forEach((pointerArea) => {
		//ポインタ表示
		pointerArea.addEventListener('mouseenter', () => {
			targetPointer.classList.add('is-active');
		});
		//ポインタ非表示
		pointerArea.addEventListener('mouseleave', () => {
			targetPointer.classList.remove('is-active');
		});
		//ポインタ移動
		pointerArea.addEventListener('mousemove', (e) => {
			targetPointer.style.top = e.clientY + 'px';
			targetPointer.style.left = e.clientX + 'px';
		});
	});
}

//関数呼び出し target:表示エリア, pointer:表示させたいポインタ
changeCursor('.js-cursor-elm01','.js-cursor-pointer01');
changeCursor('.js-cursor-elm02','.js-cursor-pointer02');

//スライダーテスト
const swiper = new Swiper('.swiper', {
	loop: true,
	slidesPerView: 3,
	spaceBetween: 30,
	pagination: {
		el: '.swiper-pagination',
		clickable: true,
	},
	navigation: {
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	},
	on: {
		//スライダーが定義された時に呼び出す
		init: ()=> {
			changeCursor('.js-cursor-elm03','.js-cursor-pointer03');
		}
	},
});
              
            
!
999px

Console