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 id="wrapper"></div>
              
            
!

CSS

              
                body,html{
  padding: 0;
  margin: 0;
}

* {
     box-sizing: border-box;
}

#wrapper {
     width: 100%;
}

// styles for all sliders
.gsapSlider {
     overflow: hidden;
     position: relative;
}

.gsap-slides {
     width: 100%;
     margin: 0;
     padding: 0;
     display: flex;
     overflow: hidden;
     li {
          width: 100%;
          background-size: cover;
     }
}

$nav: 10px;
.gsap-nav {
     padding: $nav;
     position: absolute;
     bottom: $nav;
     left: 0;
     width: 100%;
     ul {
          margin: 0;
          padding: 0;
          list-style-type: none;
          display: flex;
          width: 100%;
          justify-content: center;
          li {
               background-color: green;
               width: $nav;
               height: $nav;
               border: solid 1px white;
               border-radius: $nav/2;
               margin: 0 $nav/2;
               padding: 0;
               &.current {
                    background-color: white;
               }
               &:hover {
                    cursor: pointer;
               }
          }
     }
}
              
            
!

JS

              
                var images = ['https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-1.jpg', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-2.jpg', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-3.jpg', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-4.jpg', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-5.jpg', 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/308348/gsap-6.jpg'];

var wrapper = '#wrapper';


// GSAP SLIDER FUNCTION

function gsapSlider(imageArray, sliderWrapper, imageHeight, sliderID) {
     // create unordered list in slider
     $(sliderWrapper).append('<ul class="gsap-slides"></ul>').addClass('gsapSlider');

     // create navigation
   $(sliderWrapper).append('<div class="gsap-nav"><ul ></ul></div>');

     // count number of images in array
     var numberSlides = (imageArray.length);
     // number in rotation, taking final 'clone' slide into consideration
     var numberRotation = numberSlides + 1;
     // create unique selector for slider
     var slider = $(sliderWrapper + ' .gsap-slides');
     // unique selector for each image li 
     var image_li = $(sliderWrapper + ' .gsap-slides li');
     var navigation = $('.gsap-nav ul');

     for (var i = 0; i < (numberSlides); i++) {
          // add each image as a li and set background image and height  
          slider.append('<li style="background-image: url(' + imageArray[i] + '); height:' + imageHeight + ';"></li>');
          
      navigation.append('<li class="nav-opt nav-' + (i + 1) + '" data-index="' + (i + 1) + '"></li>')

     }

     // add 'clone' to end - repeat of first slide
     slider.append('<li style="background-image: url(' + imageArray[0] + '); height:' + imageHeight + ';"></li>');

     // set width of slider
     slider.css({
          width: numberRotation * 100 + '%'
     });
     
     $('.nav-1').addClass('current');
     
     // create timeline
     
    var sliderID = new TimelineMax({repeat: -1});
    var speed = 0.5;
    var slideWidth = -100/numberRotation;

for(var n = 1; n < numberRotation; n++){
     sliderID.addLabel('slide-' + n); 
     sliderID.to(slider, speed*7, { opacity: 1});
     sliderID.set('.nav-' + n,  {css:{className:'-=current'}});
     sliderID.set('.nav-' + (n + 1),  {css:{className:'+=current'}});
     sliderID.to(slider, speed, { x: slideWidth*n + '%'});  
}
     
// switch back to first slide
sliderID.set('.nav-' + numberSlides,  {css:{className:'-=current'}});
sliderID.set('.nav-1',  {css:{className:'+=current'}});
sliderID.set(slider, {x: '0%'});
     
// button functionality     
/*for(var b = 1; b <= numberSlides; b++){
       var navID = '.nav-' + b;
       
     
      $(navID).on("click", function(){
        var tweenD = 0 + ((b - 1) * (100/(numberSlides + 1)));
        sliderID.kill();
        TweenMax.to(slider, 0.25, {
         x: -tweenD + '%'
    });
        $('.gsap-nav li').removeClass('current');
        $(this).addClass('current');
     });
     
     
}*/
     
$('.nav-opt').click( function(){
    var index = $(this).attr('data-index');
    var tweenD = 0 + (index * (100/(numberSlides + 1)));

    sliderID.kill();
    TweenMax.to(slider, 0.25, { xPercent: -tweenD  });
    $('.gsap-nav li').removeClass('current');
    $(this).addClass('current');
});


} //end function





gsapSlider(images, wrapper, '100vh', 'tl-views');
              
            
!
999px

Console