infinite-marquee
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "infinite-marquee", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Configurable package to create an infinite marquee effect. Animated with JS or CSS.", | ||
@@ -5,0 +5,0 @@ "main": "resources/js/infinite-marquee.js", |
import InfiniteMarquee from './infinite-marquee' | ||
const marquee = new InfiniteMarquee() | ||
const marquee = new InfiniteMarquee({ css: false }) | ||
// window.addEventListener( | ||
@@ -5,0 +6,0 @@ // 'resize', |
@@ -15,3 +15,7 @@ import gsap from 'gsap' | ||
this.fillContainer() | ||
if (this.options.css) { | ||
this.fillContainerCss() | ||
} else { | ||
this.fillContainerJs() | ||
} | ||
@@ -55,3 +59,7 @@ this.animate() | ||
this.fillContainer() | ||
if (this.options.css) { | ||
this.fillContainerCss() | ||
} else { | ||
this.fillContainerJs() | ||
} | ||
} | ||
@@ -70,13 +78,17 @@ | ||
// How many content items it takes to fill the container doubled (so animation can loop infinitely) | ||
return Math.ceil(containerWidth / contentWidth) * 2 | ||
// How many content items it takes to fill the container (doubled if JS so animation can loop infinitely) | ||
if (this.options.css) { | ||
return Math.ceil(containerWidth / contentWidth) | ||
} else { | ||
return Math.ceil(containerWidth / contentWidth) * 2 | ||
} | ||
} | ||
// Create and append DOM | ||
fillContainer() { | ||
// Create and append JS DOM | ||
fillContainerJs() { | ||
const fragment = document.createDocumentFragment() | ||
for (let i = 0; i < this.fillCount; i++) { | ||
const node = this.dom.content.cloneNode(true) | ||
fragment.appendChild(node) | ||
const contentClone = this.dom.content.cloneNode(true) | ||
fragment.appendChild(contentClone) | ||
} | ||
@@ -89,10 +101,28 @@ | ||
// Create and append CSS DOM | ||
fillContainerCss() { | ||
const fragment = document.createDocumentFragment() | ||
const innerClone = this.dom.inner.cloneNode() | ||
innerClone.style.setProperty( | ||
'animation-duration', | ||
`${this.options.duration}s` | ||
) | ||
for (let i = 0; i < this.fillCount; i++) { | ||
const contentClone = this.dom.content.cloneNode(true) | ||
innerClone.appendChild(contentClone) | ||
} | ||
fragment.appendChild(innerClone) | ||
fragment.appendChild(innerClone.cloneNode(true)) | ||
this.dom.el.innerHTML = '' | ||
this.dom.el.appendChild(fragment) | ||
} | ||
// Create marquee animation | ||
animate() { | ||
if (this.options.css) { | ||
this.dom.inner.style.setProperty( | ||
'animation-duration', | ||
`${this.options.duration}s` | ||
) | ||
this.dom.el.classList.add( | ||
@@ -99,0 +129,0 @@ this.options.direction === 'left' ? 'marquee-left' : 'marquee-right' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
790957
21429
1