Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

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.

              <div id ="cell1" class="cell test">cell1<br>指定した範囲(今回はアンカー)に応じて右のアンカーリンクが連動するやつ</div>
<div id ="cell2" class="cell">cell2</div>
<div id ="cell3" class="cell">cell3</div>
<div id ="cell4" class="cell">cell4</div>
<div id ="cell5" class="cell">cell5</div>
<div id ="cell6" class="cell">cell6</div>
<ul class="fixed">
<li><a href="#cell1"></a></li>
<li><a href="#cell2"></a></li>
<li><a href="#cell3"></a></li>
<li><a href="#cell4"></a></li>
<li><a href="#cell5"></a></li>
<li><a href="#cell6"></a></li>
              body {
  background: #000;
  color: #fff;
.cell {
  height: 100vh;
#cell1 {
  background: #222;
#cell2 {
  background: #444;
#cell3 {
  background: #666;
#cell4 {
  background: #888;
#cell5 {
  background: #aaa;
#cell6 {
  background: #ccc;
  position: fixed;
  width: 20px;
  right: 20px;
  left: auto;
  top: 0;
  bottom: 0;
.fixed li {
  list-style: none;
  margin: 10px 0;
.fixed li a {
  display: block;
  background: #ff0;
  border-radius: 50%;
  height: 20px;
  width: 20px;
.fixed li a.active {
  background: #f00;
              var cells = $('.fixed a');
var cell1 = $('.fixed a[href="#cell1"]');
var cell2 = $('.fixed a[href="#cell2"]');
var cell3 = $('.fixed a[href="#cell3"]');
var cell4 = $('.fixed a[href="#cell4"]');
var cell5 = $('.fixed a[href="#cell5"]');
var cell6 = $('.fixed a[href="#cell6"]');
var position01 = $('#cell1').position();
var position02 = $('#cell2').position();
var position03 = $('#cell3').position();
var position04 = $('#cell4').position();
var position05 = $('#cell5').position();
var position06 = $('#cell6').position();

// 判定
checkPos = function(){
  var scrollPosition = $(window).scrollTop() + 10;

  if ( scrollPosition > position01.top && scrollPosition < position02.top ) {
  else if ( scrollPosition > position02.top && scrollPosition < position03.top ) {
  else if ( scrollPosition > position03.top && scrollPosition < position04.top ) {
  else if ( scrollPosition > position04.top && scrollPosition < position05.top ) {
  else if ( scrollPosition > position05.top && scrollPosition < position06.top ) {
  else if ( scrollPosition > position06.top) {

// 読み込み時に実行
window.onload = function() {

// スクロール時に実行
var timer = false;
$(window).on('scroll', function() {

  // スクロール中か判定
  if (timer !== false) {


// #で始まるアンカーをクリックした場合に処理
$('a[href^="#"]').on('click', function() {
  // スクロールの速度
  var speed = 400; // ミリ秒
  // アンカーの値取得
  var href= $(this).attr('href');
  // 移動先を取得
  var target = $(href == '#' || href == '' ? 'html' : href);
  // 移動先を数値で取得
  var position = target.offset().top;
  // スムーススクロール
  $('body,html').animate({scrollTop:position}, speed, 'swing');
  return false;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.