HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
.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%;
}
//指定エリアでマウスポインタを変更する関数 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');
}
},
});
Also see: Tab Triggers