-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b1e574
commit 1aaab92
Showing
3 changed files
with
119 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<script> | ||
//リサイズ時にアニメーションの速度を再計算 | ||
function resizeRefresh() { | ||
const target = document.body; | ||
const resizeObserver = new ResizeObserver((entries) => { | ||
entries.forEach((entry) => { | ||
calculateLoopAnimationSpeed(); | ||
}); | ||
}); | ||
resizeObserver.observe(target); | ||
} | ||
|
||
|
||
//アニメーションの速度を計算してCSS変数に | ||
function calculateLoopAnimationSpeed() { | ||
const targets = document.querySelectorAll('.js-tick'); | ||
if (!targets.length) { | ||
return; | ||
} | ||
|
||
const distance = window.innerWidth; | ||
const mql = window.matchMedia('(min-width: 801px)'); | ||
const time = mql.matches ? 18 : 9; //ここで時間を調整 | ||
const speed = distance / time; | ||
|
||
targets.forEach((target) => { | ||
const tickElems = target.querySelectorAll('.js-tick-item'); | ||
if (!tickElems.length) { | ||
return; | ||
} | ||
|
||
const total = tickElems.length - 1; | ||
|
||
tickElems.forEach((el, i) => { | ||
const elWidth = el.clientWidth; | ||
const elTime = Math.floor(elWidth / speed); | ||
el.style.setProperty('--tick-duration', `${elTime}s`); | ||
el.style.setProperty('--tick-delay', `${elTime / -2}s`); | ||
|
||
if (i === total) { | ||
el.parentNode.classList.remove('no-tick'); | ||
} | ||
|
||
}); | ||
}); | ||
} | ||
|
||
//テキストをコピーする | ||
function copyText() { | ||
const targets = document.querySelectorAll('.js-tick'); | ||
if (!targets.length) { | ||
return; | ||
} | ||
|
||
targets.forEach((target) => { | ||
const tickElems = target.querySelectorAll('.js-tick-item'); | ||
if (!tickElems.length) { | ||
return; | ||
} | ||
|
||
let length = 0; | ||
tickElems.forEach((el) => { | ||
length += el.clientWidth; | ||
el.insertAdjacentHTML('afterend', el.outerHTML); | ||
if (length > window.innerWidth) { | ||
return; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters