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 class="services-ticker-block">
  <div class="stb_line_single">
  <a href="#" class="stb-item">
        <span>Simple 1</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 2</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 3</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 4</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 5</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 6</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 7</span>
      </a>
  </div>
</div>
<div class="services-ticker-block">
  <div class="stb_line_single">
      <a href="#" class="stb-item">
        <span>Simple 8</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 9</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 10</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 11</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 12</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 13</span>
      </a>
         <a href="#" class="stb-item">
        <span>Simple 14</span>
      </a>
	      <a href="#" class="stb-item">
        <span>Simple 15</span>
      </a>
  </div>
</div>


              
            
!

CSS

              
                .services-ticker-block {
  position: relative;
  display:flex; 
  align-items:center;
  overflow-x: hidden;
}
body {
    display: flex;
    align-items: flex-start;
}
.stb_line_single {
    position: relative;
    white-space: nowrap;
    padding: 0;
    will-change: transform;
    display: flex;
    flex-direction: column;
}
.stb-item {
  padding: 0;
  font-size: 6.4rem;
  display: inline-block;
  margin-right: 10rem;

}
.stb-item:hover {
    color: #C02534;
}

              
            
!

JS

              
                gsap.utils.toArray('.stb_line_single').forEach((line, i) => {
  const links = line.querySelectorAll("a"),
        tl = horizontalLoop(links, {
          repeat: -1, 
          speed: 1 + i * 0.5,
          reversed: i ? true : false,
          paddingRight: parseFloat(gsap.getProperty(links[0], "marginRight", "px")) // otherwise first element would be right up against the last when it loops. In this layout, the spacing is done with marginRight.
        });
  links.forEach(link => {
    link.addEventListener("mouseenter", () => gsap.to(tl, {timeScale: 0, overwrite: true}));
    link.addEventListener("mouseleave", () => gsap.to(tl, {timeScale: i ? -1 : 1, overwrite: true}));
  });
});


/*
This helper function makes a group of elements animate along the x-axis in a seamless, responsive loop.

Features:
 - Uses yPercent so that even if the heights change (like if the window gets resized), it should still work in most cases.
 - When each item animates to the left or right enough, it will loop back to the other side
 - Optionally pass in a config object with values like "speed" (default: 1, which travels at roughly 100 pixels per second), paused (boolean),  repeat, reversed, and paddingRight.
 - The returned timeline will have the following methods added to it:
   - next() - animates to the next element using a timeline.tweenTo() which it returns. You can pass in a vars object to control duration, easing, etc.
   - previous() - animates to the previous element using a timeline.tweenTo() which it returns. You can pass in a vars object to control duration, easing, etc.
   - toIndex() - pass in a zero-based index value of the element that it should animate to, and optionally pass in a vars object to control duration, easing, etc. Always goes in the shortest direction
   - current() - returns the current index (if an animation is in-progress, it reflects the final index)
   - times - an Array of the times on the timeline where each element hits the "starting" spot. There's also a label added accordingly, so "label1" is when the 2nd element reaches the start.
 */
function horizontalLoop(items, config) {
	items = gsap.utils.toArray(items);
	config = config || {};
	let tl = gsap.timeline({repeat: config.repeat, paused: config.paused, defaults: {ease: "none"}, onReverseComplete: () => tl.totalTime(tl.rawTime() + tl.duration() * 100)}),
		length = items.length,
		startY = items[0].offsetLeft,
		times = [],
		heights = [],
		yPercents = [],
		curIndex = 0,
		pixelsPerSecond = (config.speed || 1) * 100,
		snap = config.snap === false ? v => v : gsap.utils.snap(config.snap || 1), // some browsers shift by a pixel to accommodate flex layouts, so for example if height is 20% the first element's height might be 242px, and the next 243px, alternating back and forth. So we snap to 5 percentage points to make things look more natural
		totalHeight, curY, distanceToStart, distanceToLoop, item, i;
	gsap.set(items, { // convert "y" to "yPercent" to make things responsive, and populate the heights/yPercents Arrays to make lookups faster.
		yPercent: (i, el) => {
			let w = heights[i] = parseFloat(gsap.getProperty(el, "height", "px"));
			yPercents[i] = snap(parseFloat(gsap.getProperty(el, "y", "px")) / w * 100 + gsap.getProperty(el, "yPercent"));
			return yPercents[i];
		}
	});
	gsap.set(items, {y: 0});
	totalHeight = items[length-1].offsetLeft + yPercents[length-1] / 100 * heights[length-1] - startY + items[length-1].offsetHeight * gsap.getProperty(items[length-1], "scaleY") + (parseFloat(config.paddingRight) || 0);
	for (i = 0; i < length; i++) {
		item = items[i];
		curY = yPercents[i] / 100 * heights[i];
		distanceToStart = item.offsetLeft + curY - startY;
		distanceToLoop = distanceToStart + heights[i] * gsap.getProperty(item, "scaleY");
		tl.to(item, {yPercent: snap((curY - distanceToLoop) / heights[i] * 100), duration: distanceToLoop / pixelsPerSecond}, 0)
		  .fromTo(item, {yPercent: snap((curY - distanceToLoop + totalHeight) / heights[i] * 100)}, {yPercent: yPercents[i], duration: (curY - distanceToLoop + totalHeight - curY) / pixelsPerSecond, immediateRender: false}, distanceToLoop / pixelsPerSecond)
		  .add("label" + i, distanceToStart / pixelsPerSecond);
		times[i] = distanceToStart / pixelsPerSecond;
	}
	function toIndex(index, vars) {
		vars = vars || {};
		(Math.abs(index - curIndex) > length / 2) && (index += index > curIndex ? -length : length); // always go in the shortest direction
		let newIndex = gsap.utils.wrap(0, length, index),
			time = times[newIndex];
		if (time > tl.time() !== index > curIndex) { // if we're wrapping the timeline's playhead, make the proper adjustments
			vars.modifiers = {time: gsap.utils.wrap(0, tl.duration())};
			time += tl.duration() * (index > curIndex ? 1 : -1);
		}
		curIndex = newIndex;
		vars.overwrite = true;
		return tl.tweenTo(time, vars);
	}
	tl.next = vars => toIndex(curIndex+1, vars);
	tl.previous = vars => toIndex(curIndex-1, vars);
	tl.current = () => curIndex;
	tl.toIndex = (index, vars) => toIndex(index, vars);
	tl.times = times;
  if (config.reversed) {
    tl.vars.onReverseComplete();
    tl.reverse();
  }
	return tl;
}
              
            
!
999px

Console