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(data-scroll)
  div.smooth-scroll(data-scroll-content)
    section.e-flex
      h1 PINNED BOILERPLATE
    section.pin.e-flex
      h1.title Montreal
    section.release
    
    section.percent
      h1.t-white.perc PERCNT #[span.dyna 00%]
    section.release-percent
    section
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Poppins:100&display=swap')
body
  background: brown
  //text-transform: uppercase

  
  
section
  width: 100vw
  height: 100vh
  position: relative
  h1
    color: #FFF
    position: absolute
    top: 20vh
    font-size: 15vw
    font-family: 'Poppins', sans-serif
    font-weight: 500
    //color: transparent
    //-webkit-text-stroke: 0.5px white
    //background: red
.release
  height: 300vh !important
  background-color: #222
  border: 1px solid #222

.pin
  z-index: 1
  height: 200vh
  background: #444
  
.e-flex
  display: flex
  align-items: center
  justify-content: center
  
.percent
  height: 200vh
  background: #1e9999
              
            
!

JS

              
                console.clear();

let h = window.innerHeight
let w = window.innerWidth


var tlAnimeText = gsap.timeline({paused:true}), 
    mySplitText = new SplitText(".title", {type:"words,chars"}), 
    chars = mySplitText.chars; ///an array of all the divs that wrap each character


  tlAnimeText
    .staggerFrom(chars, 0.8, { y: gsap.utils.wrap([-50, 100]),  rotation:  gsap.utils.wrap([-360, 180, 360]), transformOrigin: "0% 50% -50", ease: 'power.inOut' }, -0.01, 0)
    .fromTo(".title", 1, { yPercent: 301},{yPercent: 0,  ease: 'power.inOut' }, 0)
  
    //
    // Pin Works
    //-------------------------------------------------
  function pinned(scrolled){   
      let distanceSectionPin =   document.querySelector('.pin').getBoundingClientRect().top // dynamic distance between pinElem. and top page
      let distanceSectionRelease =   document.querySelector('.release').getBoundingClientRect().top //dynamic  distance between releaseEl. and top page
      
      //get statics
      let staticDistancePinned = ((scrolled * -1) - distanceSectionPin) * - 1
      let staticDistanceRelease = ((scrolled * -1) - distanceSectionRelease) * - 1
      let total = staticDistanceRelease - staticDistancePinned
      
      //console.log(scrolled +' scrolled')

        //pin pinEl. while viewport watching these element
        if(distanceSectionPin < 0 && distanceSectionRelease >  0 ){
          //transform distance in percentage ( 0 >> 0.5 >> 1)
          console.log(staticDistancePinned)
          let percentageDuration  = (scrolled - staticDistancePinned)  / total
          gsap.set('.title', { y: scrolled - staticDistancePinned })
          
          //Anime duration (.progress) based in percetange of 
          gsap.set(tlAnimeText, { progress: percentageDuration})
          //console.log(  percentageDuration )
        }
    
    
    let pinPercentage = document.querySelector('.percent').getBoundingClientRect().top
      let distanceReleasePercent = document.querySelector('.release-percent').getBoundingClientRect().top
      
      //get statics
      let staticPercent = ((scrolled * -1) - (pinPercentage - h)) * - 1
      let staticReleasePercent = ((scrolled * -1) - distanceReleasePercent) * - 1
      let totalPercent = staticReleasePercent - staticPercent
      
    
        if(pinPercentage < h && distanceReleasePercent >  0 ){
          console.log(staticPercent)
          let percntDurationPercent  = (scrolled - staticPercent)  / totalPercent
          gsap.set('.perc', { y: (scrolled - h) - staticPercent })
          $('.dyna').text(`${percntDurationPercent.toFixed(2)}`)
        }
        

} //close pinned

        


// ---------- init SMOOTH SCROLL
// ---------- init SMOOTH SCROLL
function smoothScroll() {
  if($(window).width() > 80) {
  
    const math = {
        lerp: (a, b, n) => {
            return (1 - n) * a + n * b
        },
        norm: (value, min, max) => {
              return (value - min) / (max - min)
        }
      
    }
    
    const config = {
      height: window.innerHeight,
      width: window.innerWidth
    }
    
    class Smooth {
      constructor() {
        this.bindMethods()
    
        this.data = {
          ease: 0.045,
          current: 0,
          last: 0
        }
    
        this.dom = {
          el: document.querySelector('[data-scroll]'),
          content: document.querySelector('[data-scroll-content]')
        }
    
        this.rAF = null
    
        this.init()
      }
    
      bindMethods() {
        ['scroll', 'run', 'resize']
        .forEach((fn) => this[fn] = this[fn].bind(this))
      }
    
      setStyles() {
        this.dom.el.style.position = 'fixed';
        this.dom.el.style.top = 0;
        this.dom.el.style.left = 0;
        this.dom.el.style.height = '100%'
        this.dom.el.style.width = '100%'
        this.dom.el.style.overflow = 'hidden'   
      }
    
      setHeight() {
        document.body.style.height = `${this.dom.content.offsetHeight}px`
      }
    
      resize() {
        this.setHeight()
        this.scroll()
      }
    
    
    
      scroll() {
        this.data.current = window.scrollY
      }
    
      run() {
        this.data.last = math.lerp(this.data.last, this.data.current, this.data.ease)
        this.data.last = Math.floor(this.data.last * 100) / 100
        
        const diff = this.data.current - this.data.last
        const acc = diff / config.width
        const velo =+ acc
        
          //console.log(velo)
        this.dom.content.style.transform = `translate3d(0, -${this.data.last.toFixed(0)}px, 0) `
        
        
        //call pinned
        pinned(this.data.last)
        
        this.requestAnimationFrame()
      }
        
    
      on(requestAnimationFrame = true) { 
        this.setStyles()
        this.setHeight()
        this.addEvents()
    
        requestAnimationFrame && this.requestAnimationFrame()
      }
    
      off(cancelAnimationFrame = true) {
        cancelAnimationFrame && this.cancelAnimationFrame()
    
        this.removeEvents()
      }
    
      requestAnimationFrame() {
        this.rAF = requestAnimationFrame(this.run)
      }
    
      cancelAnimationFrame() {
        cancelAnimationFrame(this.rAF)
      }
    
      destroy() {
        document.body.style.height = ''
    
        this.data = null
    
        this.removeEvents()
        this.cancelAnimationFrame()
      }
    
      resize() {
        this.setHeight()
      }
    
      addEvents() {
        window.addEventListener('resize', this.resize, { passive: true })
        window.addEventListener('scroll', this.scroll, { passive: true })
      }
    
      removeEvents() {
        window.removeEventListener('resize', this.resize, { passive: true })
        window.removeEventListener('scroll', this.scroll, { passive: true })
      }
    
      init() {
        this.on()
      }
    }
    const smooth = new Smooth()
  }
}//close menu


smoothScroll() 
              
            
!
999px

Console