Socket
Socket
Sign inDemoInstall

@andresclua/infinite-marquee-gsap

Package Overview
Dependencies
42
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

2

package.json
{
"name": "@andresclua/infinite-marquee-gsap",
"version": "0.0.5",
"version": "0.0.6",
"main": "index.js",

@@ -5,0 +5,0 @@ "author": "Andres Clua",

import gsap from 'gsap';
function verticalLoop(elements, speed) {
elements = gsap.utils.toArray(elements);
elements = gsap.utils.toArray(elements)
if (!Array.isArray(elements) || elements.length === 0) {
return null
}
config = config || {}
let firstBounds = elements[0].getBoundingClientRect(),
lastBounds = elements[elements.length - 1].getBoundingClientRect(),
top = firstBounds.top - firstBounds.height - Math.abs(elements[1].getBoundingClientRect().top - firstBounds.bottom),
lastBounds = elements[elements.length - 1].getBoundingClientRect()
if (!firstBounds || !lastBounds) {
return null
}
let top =
firstBounds.top -
firstBounds.height -
Math.abs(elements[1].getBoundingClientRect().top - firstBounds.bottom),
bottom = lastBounds.top,
distance = bottom - top,
speed = config.speed * 100 || 1,
duration = Math.abs(distance / speed),
tl = gsap.timeline({repeat: -1}),
tl = gsap.timeline({ repeat: config.repeat || -1, paused: config.paused || false }),
plus = speed < 0 ? "-=" : "+=",
minus = speed < 0 ? "+=" : "-=";
elements.forEach(el => {
let bounds = el.getBoundingClientRect(),
ratio = Math.abs((bottom - bounds.top) / distance);
if (speed < 0) {
ratio = 1 - ratio;
}
tl.to(el, {
y: plus + distance * ratio,
duration: duration * ratio,
ease: "none"
}, 0);
tl.fromTo(el, {
y: minus + distance
}, {
y: plus + (1 - ratio) * distance,
ease: "none",
duration: (1 - ratio) * duration,
immediateRender: false
}, duration * ratio)
});
return tl;
minus = speed < 0 ? "+=" : "-="
elements.forEach((el) => {
if (el) {
let bounds = el.getBoundingClientRect(),
ratio = Math.abs((bottom - bounds.top) / distance)
if (speed < 0) {
ratio = 1 - ratio
}
tl.to(
el,
{
y: plus + distance * ratio,
duration: duration * ratio,
ease: "none",
},
0
)
tl.fromTo(
el,
{
y: minus + distance,
},
{
y: plus + (1 - ratio) * distance,
ease: "none",
duration: (1 - ratio) * duration,
immediateRender: false,
},
duration * ratio
)
}
})
return tl
}
export {verticalLoop};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc