Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Dec 4, 2024
1 parent 03bd4e9 commit e0e95fc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
42 changes: 26 additions & 16 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@ const $marquee = document.getElementById('marquee')!;

const marquee = (window.m = new Marquee($marquee, {
rate: -100,
// rate: -500,
}));

window.l = loop(
marquee,
[
() => 'Contrary to popular belief, Lorem Ipsum is not simply random text',
() =>
'It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old',
() =>
'Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source',
() =>
'Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC',
],
() => {
const $separator = document.createElement('div');
$separator.innerHTML = '&nbsp•&nbsp';
return $separator;
},
// window.l = loop(
// marquee,
// [
// () =>
// 'testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest'.repeat(
// 1,
// ),
// // () =>
// // 'It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old',
// // () =>
// // 'Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source',
// // () =>
// // 'Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC',
// ],
// () => {
// const $separator = document.createElement('div');
// $separator.innerHTML = '&nbsp•&nbsp';
// return $separator;
// },
// );

marquee.appendItem(
'testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest'.repeat(
1,
),
);
13 changes: 8 additions & 5 deletions demo/src/style.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#marquee {
position: fixed;
overflow: hidden;
/* position: fixed; */
/* overflow: hidden; */
width: 200px;
margin: 0;
margin-left: 500px;
/* margin-left: 600px; */
padding: 7px 0;
font-size: 20px;
bottom: 0;
/* bottom: 0;
left: 0;
right: 0;
right: 0; */
background-color: #c80000;
color: #ffffff;
color: #000000;
font-family: Verdana, Geneva, sans-serif;
}
2 changes: 1 addition & 1 deletion src/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SizeWatcher } from './size-watcher.js';
export class Item {
constructor({ $el, direction, metadata, snapToNeighbor }) {
const $container = document.createElement('div');
$container.style.all = 'unset';
// $container.style.all = 'unset';
$container.style.display = 'block';
$container.style.opacity = '0';
$container.style.pointerEvents = 'none';
Expand Down
9 changes: 6 additions & 3 deletions src/marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { defer, deferException, toDomEl, first, last } from './helpers.js';
import { SizeWatcher } from './size-watcher.js';

const maxTranslateDistance = 500000;
// const maxTranslateDistance = 500000;
// const maxTranslateDistance = 1000;
const maxTranslateDistance = 500;
const renderInterval = 100;

export class Marquee {
Expand Down Expand Up @@ -49,9 +52,9 @@ export class Marquee {
this._visible = !!document.hidden;
this._waitingForRaf = false;
const $window = document.createElement('div');
$window.style.all = 'unset';
// $window.style.all = 'unset';
$window.style.display = 'block';
$window.style.overflow = 'hidden';
// $window.style.overflow = 'hidden';
$window.style.position = 'relative';
if (this._direction === DIRECTION.DOWN) {
$window.style.height = '100%';
Expand All @@ -67,7 +70,7 @@ export class Marquee {
this._updateWindowInverseSize();
const $moving = document.createElement('div');
this._$moving = $moving;
$moving.style.all = 'unset';
// $moving.style.all = 'unset';
$moving.style.display = 'block';
$moving.style.position = 'absolute';
$moving.style.left = '0';
Expand Down
9 changes: 8 additions & 1 deletion src/slider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DIRECTION } from './direction';

const transitionDuration = 30000;
// const transitionDuration = 30000;
const transitionDuration = 15000;

export class Slider {
constructor($el, direction) {
Expand All @@ -10,6 +11,7 @@ export class Slider {
}

setOffset(offset, rate, force) {
// force = true;
const transitionState = this._transitionState;
const rateChanged = !transitionState || transitionState.rate !== rate;
if (transitionState && !force) {
Expand All @@ -19,6 +21,8 @@ export class Slider {
}
}

// if (offset === 0) offset = 300;

if (force || rateChanged) {
if (this._direction === DIRECTION.RIGHT) {
this._$el.style.transform = `translateX(${offset}px)`;
Expand All @@ -28,10 +32,13 @@ export class Slider {

this._$el.style.transition = 'none';
this._$el.offsetLeft;
console.log('offset left', offset);
}

if (rate && (force || rateChanged)) {
this._$el.style.transition = `transform ${transitionDuration}ms linear`;

console.log('updating transition');
}

if (rate) {
Expand Down

0 comments on commit e0e95fc

Please sign in to comment.