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

              
                <nav>
  <ul>
    <li id="#slide1nav"><a>slide 1</a></li>
    <li id="#slide2nav"><a>slide 2</a></li>
    <li id="#slide3nav"><a>slide 3</a></li>
    <li id="#slide4nav"><a>slide 4</a></li>
  </ul>
</nav>


<div class="slide-container">
            
    <section id="slide1" class="slide slide1 scrollMajicFix">
                
        <div class="module-background">
          <h1 class="text1">Slide 1</h1>
        </div>
                
    </section>
            
    <section id="slide2" class="slide slide2 scrollMajicFix">
                
        <div class="module-background">
          <h1 class="text2">Slide 2</h1>
        </div>
                
    </section>
            
    <section id="slide3" class="slide slide3">
                
        <div class="module-background">
          <h1 class="text3">Slide 3.</h1>
        </div>
                
    </section>
  
    <section id="slide4" class="slide slide4">
                
      <div class="module-background">
        <h1 class="text4">Slide 4</h1>
      </div>
                
 </section>
  
  
</div>



 

  
        
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
}

h1.page{color:black;text-align:center;padding-top:100px}

.scrollMajicFix{top:0 !important}


nav {
  position: fixed;
  top: 20px;
  width: 50%;
  z-index: 999;
  left: 50%;
  transform: translate(-50%, 0)
}

ul {
  display: flex;
  justify-content: space-between;
}

li {
  list-style: none;
  background-color: white;
}

li a {
  padding: 20px;
}


.slide{
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    position: relative;
}



.module-background {
    display: flex;
    align-items: center; 
    justify-content: center;
    position:relative;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
}

.module-background h1 {
    position:absolute;
    color: white;
    font-size:30px;
}


.slide1 .module-background {
    background-color: green;
}

.slide2  .module-background {
    background-color: blue;
}

.slide3  .module-background {
    background-color: orange;
}

.slide4  .module-background {
    background-color: brown;
}
              
            
!

JS

              
                
    var ctrl = new ScrollMagic.Controller({   
    });
  
 
    // This each sets the animation
    $('.slide').each(function(index,element) {  
      
      
      
          ////////// scroll up //////////

          new ScrollMagic.Scene({
              triggerHook: 0,
              triggerElement: this,
              offset:-50 // small offset added to prevent overscrolling accidentally triggering
          })
          .on('leave', function () {
                TweenLite.to(window, .5, {scrollTo:{y:$(window).height() * (index-1), autoKill:false},ease: Linear.easeNone})
          })
          .addTo(ctrl);  // scene end




          //////////scroll down //////////

           new ScrollMagic.Scene({
                triggerElement: this,
                triggerHook: 0,
                offset:50 // small offset added to prevent overscrolling accidentally triggering
            })
            .on('enter', function () {
                 TweenLite.to(window, .5, {scrollTo:{y:$(window).height() * (index+1), autoKill:false},ease: Linear.easeNone});   
            })
            .addTo(ctrl); // scene end
       
      
      
      
            ////////// Main Nav Click transition //////////
            
            //slide 1 link
            var slide1Nav = document.getElementById("#slide1nav")
            
            slide1Nav.addEventListener('click', event => {

                var slide1NavMove = new TimelineMax()

                      slide1NavMove
                        TweenLite.to(window, 1, {scrollTo:"#slide1"});

              });
      
              //slide 2 link
              var slide2Nav = document.getElementById("#slide2nav")

              slide2Nav.addEventListener('click', event => {

                  var slide2NavMove = new TimelineMax()

                        slide2NavMove
                          TweenLite.to(window, 1, {scrollTo:"#slide2"});

                });
      
      
              //slide 3 link
              var slide3Nav = document.getElementById("#slide3nav")

              slide3Nav.addEventListener('click', event => {

                  var slide3NavMove = new TimelineMax()

                        slide3NavMove
                          TweenLite.to(window, 1, {scrollTo:"#slide3"});

                });
      
      
                //slide 4 link
                var slide4Nav = document.getElementById("#slide4nav")

                slide4Nav.addEventListener('click', event => {

                    var slide4NavMove = new TimelineMax()

                          slide4NavMove
                            TweenLite.to(window, 1, {scrollTo:"#slide4"});

                  });
      
      
    }); //slide each
  
  




/// If clicked
var elementIsClicked = false;
function clickHandler(){
  elementIsClicked = true;
}

var element = document.getElementById('#slide2nav');
element.addEventListener('click', clickHandler);


function clickHandler(){
    if(element){
        console.log('Clicked'); ///works
    } else {
        console.log('Not'); ///Not working - this is where I'd want to put my scrollmagic stuff.
    }
}

              
            
!
999px

Console