GSAP - Infinite Textbanner
Aus Wikizone
Version vom 22. April 2021, 12:13 Uhr von 109.192.169.230 (Diskussion)
aka Textscroller, Marquee Text
https://codepen.io/kholja/pen/JjEZBeN?editors=1111 https://greensock.com/forums/topic/10230-what-is-the-best-method-for-scrolling-text-horizontally-across-a-div/
// Add Clone at the End
// Scale text to at least 100% (container overflows and nowrap)
// Move 100% text-width to the left
$(window).resize(resizeHandler);
gsap.registerPlugin('ScrollTrigger');
gsap.defaultEase = "power4.Out";
var time = 12;
// Set text animation
function rollOne(){
//
var tlOne = gsap.timeline();
var $textOne = $(".text-one");
$textOne.css({width:"auto"});
var textWidth = $textOne.width();
console.log(textWidth);
$textOne.width(textWidth);
tlOne.to('.text-one',time,{
x:-textWidth,
ease: Linear.easeNone,
repeat: -1
});
return tlOne;
}
// Create a clone and roll it
function cloneOne(){
$clone = $(".text-one").clone().appendTo(".banner-one");
$clone.addClass("clone");
rollOne();
}
function resizeHandler(){
var progress = tlOne.progress(); //record timeline progress
tlOne.time(0).kill(); //rewind and kill the original tween.
//time = 5;
rollOne().progress(progress); //create a new tween based on the new size, and jump to the same progress value.
}
cloneOne();
GSDevTools.create();