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

              
                div#app
  header
    span.
      {{ currentNavi }}
  main
    section(id="section_01")
      span コンテンツ1のエリアです
    section(id="section_02")
      span コンテンツ2のエリアです
    section(id="section_03")
      span コンテンツ3のエリアです
    section(id="section_04")
      span コンテンツ4のエリアです
    section(id="section_05")
      span コンテンツ5のエリアです
  
              
            
!

CSS

              
                header
  position: fixed
  background: white
  width: 100%
  height: 40px
  display: flex
  justify-content: center
  align-items: center
  font-size: 14px
  font-weight: bold
main
  padding: 40px 0 0 0
  section
    height: calc(100vh - 40px)
    padding: 20px 10px
    &:nth-child(odd)
      background: skyblue
    &:nth-child(even)
      background: palegreen
  
  
              
            
!

JS

              
                var vueModel = new Vue({
  el: '#app',
  data() {
    return {
      scrollY: 0,
      sectionOffsetTop: []
    }
  },
  computed: {
    currentNavi() {
      if(this.scrollY >= this.sectionOffsetTop[0] && this.scrollY < this.sectionOffsetTop[1]) {
        return 'コンテンツ1'
      } else if(this.scrollY >= this.sectionOffsetTop[1] && this.scrollY < this.sectionOffsetTop[2]) {
        return 'コンテンツ2'
      } else if(this.scrollY >= this.sectionOffsetTop[2] && this.scrollY < this.sectionOffsetTop[3]) {
        return 'コンテンツ3'
      } else if(this.scrollY >= this.sectionOffsetTop[3] && this.scrollY < this.sectionOffsetTop[4]) {
        return 'コンテンツ4'
      } else if(this.scrollY >= this.sectionOffsetTop[4]) {
        return 'コンテンツ5'
      } else {
        return 'スクロールすると現在のコンテンツ名が表示されます'
      }
    }
  },
  mounted() {
    window.addEventListener('scroll', () => {
      this.pushScrollY();
    });
    window.addEventListener('resize', () => {
      this.pushScrollY();
    });
    this.pushElementOffsetTop();
  },
  methods: {
    pushScrollY() {
      this.scrollY = window.scrollY;
    },
    pushElementOffsetTop() {
      const targets = [
        'section_01',
        'section_02',
        'section_03',
        'section_04',
        'section_05'
      ];
      targets.forEach(target => {
        const element = document.getElementById(target)
        const offsetTop = Math.round(window.scrollY + element.getBoundingClientRect().top);
        this.sectionOffsetTop.push(offsetTop);
      });
    }
  }
});
              
            
!
999px

Console