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="portfolio-wrap">
  <button type="button" name="button" id="left"><-</button>
    <ul id="portfolio" class="portfolio">
        <li>list item 1</li>
        <li>list item 2</li>
        <li>list item 3</li>
        <li>list item 4</li>
        <li>list item 5</li>
        <li>list item 6</li>
        <li>list item 7</li>
        <li>list item 8</li>
        <li>list item 9</li>
        <li>list item 10</li>
        <li>list item 11</li>
        <li>list item 12</li>
        <li>list item 13</li>
        <li>list item 14</li>
        <li>list item 15</li>
        <li>list item 16</li>
        <li>list item 17</li>
        <li>list item 18</li>
        <li>list item 19</li>
        <li>list item 20</li>
        <li>list item 21</li>
        <li>list item 22</li>
        <li>list item 23</li>
        <li>list item 24</li>
        <li>list item 25</li>
        <li>list item 26</li>
        <li>list item 27</li>
        <li>list item 28</li>
        <li>list item 29</li>
    </ul>
  <button type="button" name="button" id="right">-></button>
</div>
              
            
!

CSS

              
                body {
margin:0;
}

#portfolio-wrap {
		height:100vh;
    width:100%;
		overflow:hidden;
		margin:0 auto;
    text-align:center;
    font-size:48px;
    position:absolute;
  
  
	}

#portfolio-wrap ul {
  margin:0;
  padding:0;
  overflow:hidden;
  z-index:1;
}

#portfolio-wrap ul li {
  margin:0px;
  padding:0;
  list-style:none;
  background:#ccc;
  position: absolute;
  width:100%;
  line-height:20vh;
  height:20vh;
}

#left{
  position:absolute;
  z-index:10;
  left:10px;
  top:10px;
}

#right {
  position:absolute;
  z-index:10;
  right:10px;
  top:10px;
}
              
            
!

JS

              
                console.clear();

gsap.registerPlugin(Draggable);

var wrapper = document.querySelector(".portfolio");
var right = document.querySelector("#right");
var left = document.querySelector("#left");
var boxes = document.querySelectorAll(".portfolio li");

var boxHeightValue = document.querySelector('.portfolio li');
var boxHeight = boxHeightValue.clientHeight;
var imgHeight = boxHeight;
var wrapHeight = boxes.length * boxHeight;
var viewHeight = wrapper.offsetHeight;

gsap.set(wrapper, {height: '100vh'});

for (var i = 0; i < boxes.length; i++) {
  let box = boxes[i];
  gsap.set(box, {y: i * boxHeight, top: -boxHeight });
}

var wrapProgress = gsap.utils.wrap(0, 1);
var snapBox = gsap.utils.snap(boxHeight);
var clickAnimation = gsap.set({}, {});
var proxy = document.createElement("div");
var props = gsap.getProperty(proxy);

var animation = gsap.to(".portfolio li", {
  duration: 1,
  y: "+=" + wrapHeight,
  ease: Linear.easeNone,
  paused: true,
  repeat: -1,
  modifiers: {
    y: function(y, target) {
      y = parseFloat(y) % wrapHeight;
      return y + "px";
    }
  }
}).progress(1 / boxes.length);

Draggable.create(proxy, {
  // type: "x", 
  trigger: "#portfolio-wrap",
  throwProps: true,
  onDrag: updateProgress,
  onThrowUpdate: updateProgress,
  snap: {
    y: snapBox
  }
});

left.addEventListener('click', animateCarousel.bind(null, -1));
right.addEventListener('click', animateCarousel.bind(null, 1));

function updateProgress() {  
  animation.progress(wrapProgress(props("y") / wrapHeight));
}

function animateCarousel(direction) {
  
  clickAnimation.kill();
  
  clickAnimation = gsap.to(proxy, {
    duration: 0.2,
    y: snapBox(props("y") + direction * boxHeight),
    onUpdate: updateProgress
  });  
}



              
            
!
999px

Console